4 from string
import Template
8 def save_tmp_yaml(name
, data
):
10 Save a yaml file into a file to be declare in openvim
11 :param name: file name
15 with
open(name
, "w") as text_file
:
19 def delete_tmp_yaml(name
):
21 Delete yaml form Filesystem
22 :param name: File name
25 execute_local('rm {}'.format(name
))
28 def search_host_in_env_var():
30 Search for OPENVIM_TEST_HOST_X env var declare by pre_create_host fixture with the host id after creation.
31 :return: All env vars founded
33 return search('OPENVIM_TEST_HOST_')
36 def template_substitute(file_path
, values
):
38 Modify a Yaml template with values.
39 :param file_path: template file
40 :param values: values to be substituted
41 :return: a string with the file content modified
43 with
open(file_path
, 'r') as server_yaml
:
44 template
= Template(server_yaml
.read())
45 server_yaml
= template
.safe_substitute(values
)
51 Search for environment vars.
52 :param reg_ex: regular expresion to be applied during the search
53 :return: return results
56 for key
in os
.environ
:
58 result
[key
] = os
.environ
[key
]
64 Parse an UUID value from a string given.
65 :param data: String to be evaluated
66 :return: the uuid value
68 match
= re
.compile(r
'[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}', re
.I
).findall(data
)
70 data
= match
[0].replace(' ', '')
71 data
= data
.replace('\n', '')
79 Parse test config file
80 :param data: config file path
83 with
open(data
, 'r') as stream
:
85 return yaml
.load(stream
)
86 except yaml
.YAMLError
as exc
:
92 Parse vm id IP from openvim client.
96 openvim_path
= os
.path
.join(os
.environ
['OPENVIM_ROOT_FOLDER'], 'openvim')
97 ip
= execute_local("{} vm-list {} -vvv | grep ip_address:".format(openvim_path
, vm_id
))
98 ip
= ip
.replace('ip_address:', '')
99 ip
= ip
.replace(' ', '')
103 def get_net_status(net_id
):
105 Parse a net status from openvim client
106 :param net_id: network id
109 openvim_path
= os
.path
.join(os
.environ
['OPENVIM_ROOT_FOLDER'], 'openvim')
110 net_status
= execute_local("{} net-list {} -vvv | grep status:".format(openvim_path
, net_id
))
111 net_status
= net_status
.replace('status:', '')
112 net_status
= net_status
.replace(' ', '')