blob: 2a3d23faa2140f963f6bb34a39bbbe747f96300e [file] [log] [blame]
yadavmr58af6b12019-09-18 15:33:25 +05301# -*- coding: utf-8 -*-
2
3##
4# Copyright 2019 Tech Mahindra Limited
5#
6# All Rights Reserved.
7#
8# Licensed under the Apache License, Version 2.0 (the "License"); you may
9# not use this file except in compliance with the License. You may obtain
10# a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17# License for the specific language governing permissions and limitations
18# under the License.
19##
20
21## Change log:
yadavmrf3ec8f42020-01-30 16:07:59 +053022# Jayant Madavi, Mrityunjay Yadav : MY00514913@techmahindra.com
23##̥
24
yadavmr58af6b12019-09-18 15:33:25 +053025
yadavmr07847332019-11-28 12:01:48 +053026import random
yadavmr58af6b12019-09-18 15:33:25 +053027from haikunator import Haikunator
yadavmrf3ec8f42020-01-30 16:07:59 +053028import yaml
29from os.path import basename
30import hashlib
31
32from robot.api import logger
33from robot.api.deco import keyword
yadavmr58af6b12019-09-18 15:33:25 +053034
35
36def generate_name():
37 haikunator = Haikunator()
38 name = haikunator.haikunate(delimiter='_', token_length=2)
39 return name
yadavmr07847332019-11-28 12:01:48 +053040
41
42def get_random_item_from_list(l):
43 assert isinstance(l, list), "List should be provided"
44 return random.choice(l)
yadavmrf3ec8f42020-01-30 16:07:59 +053045
46
47def get_scaled_vnf(nsr):
48 nsr = yaml.load(nsr)
49 if 'scaling-group' in nsr['_admin']:
50 return nsr['_admin']['scaling-group'][0]['nb-scale-op']
51 else:
52 return 0
53
54
55@keyword('Get File Name From Path')
56def get_filename(path):
57 filename = basename(path)
58 return filename, filename.split('.')[0]
59
60
61@keyword('Generate MD5')
62def generate_md5(fpath):
63 hash_md5 = hashlib.md5()
64 with open(fpath, "rb") as f:
65 for chunk in iter(lambda: f.read(1024), b""):
66 hash_md5.update(chunk)
67 return hash_md5.hexdigest()