4 from robot.libraries.BuiltIn import BuiltIn
5 from robot.api import logger
7 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '../libraries/common'))
8 import common_utils # noqa
9 from decorators_for_robot_functionalities import * # noqa
10 from test_constants import * # noqa
11 from execute_command import execute_command # noqa
14 execute = BuiltIn().get_library_instance('execute_command')
15 stack_infos = BuiltIn().get_library_instance('stack_infos')
16 infra_int_if = stack_infos.get_infra_int_if()
17 infra_ext_if = stack_infos.get_infra_ext_if()
18 infra_storage_if = stack_infos.get_infra_storage_if()
21 def tc_001_danmnet_object_check():
22 steps = ['step1_inspect_clusternetworks',
23 'step2_inspect_tenantconfigs',
24 'step3_inspect_tenantnetworks']
25 BuiltIn().run_keyword("tc_001_danmnet_object_check.Setup")
26 common_utils.keyword_runner(steps)
30 cnet_test = common_utils.get_helm_chart_content("default/clusternetwork-test")
31 danm_utils.compare_test_data(cnet_test, clusternetworks_properties)
33 cnet_test_error = common_utils.get_helm_chart_content("default/clusternetwork-test-error")
34 danm_utils.compare_test_data(cnet_test_error, clusternetworks_error_properties)
36 tenantconfig_test = common_utils.get_helm_chart_content("default/tenantconfig-test")
37 danm_utils.compare_test_data(tenantconfig_test, tenantconfig_properties)
39 tenantconfig_test_error = common_utils.get_helm_chart_content("default/tenantconfig-test-error")
40 danm_utils.compare_test_data(tenantconfig_test_error, tenantconfig_error_properties)
42 tenantnetwork_test = common_utils.get_helm_chart_content("default/tenantnetwork-test")
43 danm_utils.compare_test_data(tenantnetwork_test, tenantnetwork_properties)
45 tenantnetwork_test_error = common_utils.get_helm_chart_content("default/tenantnetwork-test-error")
46 danm_utils.compare_test_data(tenantnetwork_test_error, tenantnetwork_error_properties)
49 def step1_inspect_clusternetworks():
50 logger.info("Deploying valid ClusterNetwork manifests fetched from helm chart \'clusternetwork-test\'.")
51 replace_ifaces_in_fetched_chart_templates("/tmp/clusternetwork-test/templates/*")
52 danm_utils.create_resources_from_fetched_chart_templates("/tmp/clusternetwork-test/templates")
53 for cnet in clusternetworks_properties:
54 cnet_name = clusternetworks_properties[cnet]['name']
55 count = danm_utils.get_resource_count(resource_type="clusternetwork", resource_name=cnet_name)
57 raise Exception("ClusterNetwork " + cnet_name + " does not exist, but it should!")
58 logger.info("ClusterNetwork " + cnet_name + " exists as expected.")
59 danm_utils.check_host_interfaces(clusternetworks_properties)
61 logger.info("Deploying invalid ClusterNetwork manifests fetched from helm chart \'clusternetwork-test-error\'."
63 danm_utils.create_resources_from_fetched_chart_templates("/tmp/clusternetwork-test-error/templates")
64 for cnet in clusternetworks_error_properties:
65 cnet_name = clusternetworks_error_properties[cnet]['name']
66 count = danm_utils.get_resource_count(resource_type="clusternetworks", resource_name=cnet_name)
68 raise Exception("ClusterNetwork " + cnet_name + " exists, but it should not!")
69 logger.info("ClusterNetwork " + cnet_name + " does not exist, as expected.")
71 danm_utils.delete_resources_by_manifest_path("/tmp/clusternetwork-test/templates")
74 def step2_inspect_tenantconfigs():
75 logger.info("Deploying valid TenantConfig manifests fetched from helm chart \'tenantconfig-test\'.")
76 replace_ifaces_in_fetched_chart_templates("/tmp/tenantconfig-test/templates/*")
77 danm_utils.create_resources_from_fetched_chart_templates("/tmp/tenantconfig-test/templates")
78 for tconf in tenantconfig_properties:
79 tconf_name = tenantconfig_properties[tconf]['name']
80 count = danm_utils.get_resource_count(resource_type="tenantconfig", resource_name=tconf_name)
82 raise Exception("TenantConfig " + tconf_name + " does not exist, but it should!")
83 logger.info("TenantConfig " + tconf_name + " exists as expected.")
85 logger.info("Deploying invalid TenantConfig manifests fetched from helm chart \'tenantconfig-test-error\'. "
87 danm_utils.create_resources_from_fetched_chart_templates("/tmp/tenantconfig-test-error/templates")
88 for tconf in tenantconfig_error_properties:
89 tconf_name = tenantconfig_error_properties[tconf]['name']
90 count = danm_utils.get_resource_count(resource_type="tenantconfig", resource_name=tconf_name)
92 raise Exception("TenantConfig " + tconf_name + " exists, but it shouldn't!")
93 logger.info("TenantConfig " + tconf_name + " does not exist, as expected.")
96 @pabot_lock("health_check_1")
97 def step3_inspect_tenantnetworks():
98 danm_utils.delete_all_resources("tenantconfig")
99 danm_utils.create_resources_from_fetched_chart_templates("/tmp/tenantconfig-test/templates/tconf_05.yaml")
101 # TenantNetwork-s with TenantConfig without vlan/vxlan
102 logger.info("Deploying valid TenantNetwork manifests fetched from helm chart \'tenantnetwork-test\'.")
103 replace_ifaces_in_fetched_chart_templates("/tmp/tenantnetwork-test/templates/*")
104 danm_utils.create_resources_from_fetched_chart_templates("/tmp/tenantnetwork-test/templates")
105 for tnet in tenantnetwork_properties:
106 tnet_name = tenantnetwork_properties[tnet]['name']
107 count = danm_utils.get_resource_count(resource_type="tenantnetwork", resource_name=tnet_name)
109 raise Exception("TenantNetwork " + tnet_name + " does not exist, but it should!")
110 logger.info("TenantNetwork " + tnet_name + " exists as expected.")
112 logger.info("Deploying invalid TenantNetwork manifests fetched from helm chart \'tenantnetwork-test-error\'. "
114 danm_utils.create_resources_from_fetched_chart_templates("/tmp/tenantnetwork-test-error/templates")
115 for tnet in tenantnetwork_error_properties:
116 tnet_name = tenantnetwork_error_properties[tnet]['name']
117 count = danm_utils.get_resource_count(resource_type="tenantnetwork", resource_name=tnet_name)
119 raise Exception("TenantNetwork " + tnet_name + " exists, but it shouldn't!")
120 logger.info("TenantNetwork " + tnet_name + " does not exist, as expected.")
122 danm_utils.delete_resources_by_manifest_path("/tmp/tenantnetwork-test/templates")
123 # TenantNetwork-s with TenantConfig with vlan/vxlan
124 danm_utils.create_resources_from_fetched_chart_templates("/tmp/tenantconfig-test/templates/tconf_07.yaml")
125 danm_utils.delete_resources_by_manifest_path("/tmp/tenantconfig-test/templates/tconf_05.yaml")
126 danm_utils.create_resources_from_fetched_chart_templates("/tmp/tenantnetwork-test/templates/")
127 danm_utils.check_host_interfaces(tenantnetwork_properties)
129 # cleanup after ourselves
130 danm_utils.delete_resources_by_manifest_path("/tmp/tenantnetwork-test/templates")
131 # redeploy the default TenantConfig 'danm-tenant-config' after we finish
132 execute.execute_unix_command("kubectl create -f /var/lib/caas/manifests/danm-tenant-config.yaml")
133 danm_utils.delete_resources_by_manifest_path("/tmp/tenantconfig-test/templates/tconf_07.yaml")
137 def replace_ifaces_in_fetched_chart_templates(path):
138 execute.execute_unix_command("sed -i 's/{{ .Values.infra_int_if }}/" + infra_int_if + "/g' " + path)
139 execute.execute_unix_command("sed -i 's/{{ .Values.infra_ext_if }}/" + infra_ext_if + "/g' " + path)
140 execute.execute_unix_command("sed -i 's/{{ .Values.infra_storage_if }}/" + infra_storage_if + "/g' " + path)