1 # -*- coding: utf-8 -*-
4 # Copyright 2019 Tech Mahindra Limited
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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
22 # Jayant Madavi, Mrityunjay Yadav : MY00514913@techmahindra.com
27 from haikunator
import Haikunator
29 from os
.path
import basename
32 from robot
.api
import logger
33 from robot
.api
.deco
import keyword
37 haikunator
= Haikunator()
38 name
= haikunator
.haikunate(delimiter
='_', token_length
=2)
42 def get_random_item_from_list(l
):
43 assert isinstance(l
, list), "List should be provided"
44 return random
.choice(l
)
47 def get_scaled_vnf(nsr
):
49 if 'scaling-group' in nsr
['_admin']:
50 return nsr
['_admin']['scaling-group'][0]['nb-scale-op']
55 @keyword('Get File Name From Path')
56 def get_filename(path
):
57 filename
= basename(path
)
58 return filename
, filename
.split('.')[0]
61 @keyword('Generate MD5')
62 def 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()