Bug 2327 fix to verify ipaddress in sol003_02 testsuite
[osm/tests.git] / robot-systest / resources / basic_01-crud_operations_on_vim_targets_data.py
1 # Licensed under the Apache License, Version 2.0 (the "License");
2 # you may not use this file except in compliance with the License.
3 # You may obtain a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS,
9 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 # See the License for the specific language governing permissions and
11 # limitations under the License.
12
13 import os
14 from pathlib import Path
15 import yaml
16 from common_helpers import get_prometheus_info
17
18
19 # Prometheus host and port
20 (prometheus_host, prometheus_port) = get_prometheus_info()
21
22 # VIM configuration
23 cloud_type = os.environ.get("CLOUD_TYPE", "openstack")
24 if cloud_type == "openstack":
25 # Openstack VIM
26 vim_account_type = "openstack"
27 vim_name_prefix = "basic01"
28 # Get credentias from Openstack Clouds file
29 os_cloud = os.environ.get("OS_CLOUD")
30 clouds_file_paths = ["./clouds.yaml", str(Path.home()) + "/.config/openstack/clouds.yaml", "/etc/openstack/clouds.yaml"]
31 for path in clouds_file_paths:
32 clouds_file_path = Path(path)
33 if clouds_file_path.exists():
34 break
35 if not clouds_file_path.exists():
36 raise Exception("Openstack clouds file not found")
37 with clouds_file_path.open() as clouds_file:
38 clouds = yaml.safe_load(clouds_file)
39 if not os_cloud in clouds["clouds"]:
40 raise Exception("Openstack cloud '" + os_cloud + "' not found")
41 cloud = clouds["clouds"][os_cloud]
42 if not "username" in cloud["auth"]:
43 raise Exception("Username not found in Openstack cloud '" + os_cloud + "'")
44 vim_user = cloud["auth"]["username"]
45 if not "password" in cloud["auth"]:
46 raise Exception("Password not found in Openstack cloud '" + os_cloud + "'")
47 vim_password = cloud["auth"]["password"]
48 if not "auth_url" in cloud["auth"]:
49 raise Exception("Auth url not found in Openstack cloud '" + os_cloud + "'")
50 vim_auth_url = cloud["auth"]["auth_url"]
51 if not "project_name" in cloud["auth"]:
52 raise Exception("Project name not found in Openstack cloud '" + os_cloud + "'")
53 vim_tenant = cloud["auth"]["project_name"]
54 vim_user_domain_name = cloud["auth"]["user_domain_name"] if "user_domain_name" in cloud["auth"] else None
55 vim_project_domain_name = cloud["auth"]["project_domain_name"] if "project_domain_name" in cloud["auth"] else None
56 vim_insecure = True if "verify" in cloud and not cloud["verify"] else None
57
58 # Extra config
59 vim_config_dict = {}
60 vim_config_dict["vim_network_name"] = os.environ.get("VIM_MGMT_NET")
61 if vim_project_domain_name:
62 vim_config_dict["project_domain_name"] = vim_project_domain_name
63 if vim_user_domain_name:
64 vim_config_dict["user_domain_name"] = vim_user_domain_name
65 if vim_insecure:
66 vim_config_dict["insecure"] = True
67 vim_config = "'{}'".format(yaml.safe_dump(vim_config_dict, default_flow_style=True, width=10000).rstrip('\r\n'))
68
69 elif cloud_type == "azure":
70 # Azure VIM
71 vim_account_type = "azure"
72 vim_name_prefix = "basic01"
73 vim_auth_url = "http://www.azure.com"
74 vim_user = os.environ.get("AZURE_CLIENT_ID")
75 vim_password = os.environ.get("AZURE_SECRET")
76 vim_tenant = os.environ.get("AZURE_TENANT")
77
78 # Extra config
79 vim_config_dict = {}
80 if "RESOURCE_GROUP" in os.environ:
81 vim_config_dict["resource_group"] = os.environ.get("RESOURCE_GROUP")
82 if "AZURE_REGION" in os.environ:
83 vim_config_dict["region_name"] = os.environ.get("AZURE_REGION")
84 if "AZURE_SUBSCRIPTION_ID" in os.environ:
85 vim_config_dict["subscription_id"] = os.environ.get("AZURE_SUBSCRIPTION_ID")
86 if "VNET_NAME" in os.environ:
87 vim_config_dict["vnet_name"] = os.environ.get("VNET_NAME")
88 if "AZURE_FLAVORS_PATTERN" in os.environ:
89 vim_config_dict["flavors_pattern"] = os.environ.get("AZURE_FLAVORS_PATTERN")
90 vim_config = "'{}'".format(yaml.safe_dump(vim_config_dict, default_flow_style=True, width=10000).rstrip('\r\n'))
91
92 else:
93 raise Exception("VIM type not supported: '" + cloud_type + "'")