diff options
-rw-r--r-- | sdnvpn/lib/config.py | 4 | ||||
-rw-r--r-- | sdnvpn/lib/utils.py | 46 | ||||
-rw-r--r-- | sdnvpn/test/functest/run_sdnvpn_tests.py | 47 |
3 files changed, 85 insertions, 12 deletions
diff --git a/sdnvpn/lib/config.py b/sdnvpn/lib/config.py index 99e5d00..9659fc3 100644 --- a/sdnvpn/lib/config.py +++ b/sdnvpn/lib/config.py @@ -54,6 +54,10 @@ class CommonConfig(object): self.custom_flavor_ram = 1024 self.custom_flavor_disk = 10 self.custom_flavor_vcpus = 1 + self.neutron_nw_quota = -1 + self.neutron_subnet_quota = -1 + self.neutron_port_quota = -1 + self.nova_instances_quota_class = -1 commonCfgInstance = None diff --git a/sdnvpn/lib/utils.py b/sdnvpn/lib/utils.py index e241d79..371f3ed 100644 --- a/sdnvpn/lib/utils.py +++ b/sdnvpn/lib/utils.py @@ -681,3 +681,49 @@ def is_fail_mode_secure(): 'in {} node'.format(openstack_node.name)) is_secure[openstack_node.name] = False return is_secure + + +def update_nw_subnet_port_quota(neutron_client, tenant_id, nw_quota, + subnet_quota, port_quota): + json_body = {"quota": { + "network": nw_quota, + "subnet": subnet_quota, + "port": port_quota + }} + + try: + neutron_client.update_quota(tenant_id=tenant_id, + body=json_body) + return True + except Exception as e: + logger.error("Error [update_nw_subnet_port_quota(neutron_client," + " '%s', '%s', '%s', '%s')]: %s" % + (tenant_id, nw_quota, subnet_quota, port_quota, e)) + return False + + +def update_instance_quota_class(nova_client, instances_quota): + try: + nova_client.quota_classes.update("default", instances=instances_quota) + return True + except Exception as e: + logger.error("Error [update_instance_quota_class(nova_client," + " '%s' )]: %s" % (instances_quota, e)) + return False + + +def get_neutron_quota(neutron_client, tenant_id): + try: + return neutron_client.show_quota(tenant_id=tenant_id)['quota'] + except Exception as e: + logger.error("Error in getting neutron quota for tenant " + " '%s' )]: %s" % (tenant_id, e)) + raise + + +def get_nova_instances_quota(nova_client): + try: + return nova_client.quota_classes.get("default").instances + except Exception as e: + logger.error("Error in getting nova instances quota: %s" % e) + raise diff --git a/sdnvpn/test/functest/run_sdnvpn_tests.py b/sdnvpn/test/functest/run_sdnvpn_tests.py index cff6a27..1a1d8f3 100644 --- a/sdnvpn/test/functest/run_sdnvpn_tests.py +++ b/sdnvpn/test/functest/run_sdnvpn_tests.py @@ -16,8 +16,10 @@ import traceback import yaml from functest.core import feature as base +from functest.utils import openstack_utils as os_utils from sdnvpn.lib import config as sdnvpn_config from sdnvpn.lib.gather_logs import gather_logs +from sdnvpn.lib import utils as test_utils COMMON_CONFIG = sdnvpn_config.CommonConfig() @@ -28,21 +30,32 @@ class SdnvpnFunctest(base.Feature): def execute(self): - cmd_line = "neutron quota-update --subnet -1 --network -1 --port -1" - self.__logger.info("Setting subnet/net quota to unlimited : %s" - % cmd_line) - cmd = os.popen(cmd_line) - output = cmd.read() - self.__logger.debug(output) + nova_client = os_utils.get_nova_client() + neutron_client = os_utils.get_neutron_client() + + tenant_id = os_utils.get_tenant_id(os_utils.get_keystone_client(), + os.environ['OS_PROJECT_NAME']) + + neutron_quota = test_utils.get_neutron_quota(neutron_client, tenant_id) + (neutron_nw_quota, neutron_subnet_quota, neutron_port_quota) = ( + neutron_quota['network'], neutron_quota['subnet'], + neutron_quota['port']) + instances_quota = test_utils.get_nova_instances_quota(nova_client) + + self.__logger.info("Setting net/subnet/port quota to unlimited") + test_utils.update_nw_subnet_port_quota( + neutron_client, + tenant_id, + COMMON_CONFIG.neutron_nw_quota, + COMMON_CONFIG.neutron_subnet_quota, + COMMON_CONFIG.neutron_port_quota) # Workaround for # https://jira.opnfv.org/projects/SDNVPN/issues/SDNVPN-115 - cmd_line = "nova quota-class-update --instances -1 default" - self.__logger.info("Setting instances quota to unlimited : %s" - % cmd_line) - cmd = os.popen(cmd_line) - output = cmd.read() - self.__logger.debug(output) + self.__logger.info("Setting instances quota class to unlimited") + test_utils.update_instance_quota_class( + nova_client, + COMMON_CONFIG.nova_instances_quota_class) with open(COMMON_CONFIG.config_file) as f: config_yaml = yaml.safe_load(f) @@ -80,6 +93,16 @@ class SdnvpnFunctest(base.Feature): if status == "FAIL": overall_status = "FAIL" + self.__logger.info("Resetting subnet/net/port quota") + test_utils.update_nw_subnet_port_quota(neutron_client, + tenant_id, + neutron_nw_quota, + neutron_subnet_quota, + neutron_port_quota) + + self.__logger.info("Resetting instances quota class") + test_utils.update_instance_quota_class(nova_client, instances_quota) + try: installer_type = str(os.environ['INSTALLER_TYPE'].lower()) if installer_type in ["fuel", "apex"]: |