3 # Copyright (c) 2017 Okinawa Open Laboratory and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # pylint: disable=missing-docstring
12 """vrouter testcase implementation."""
20 from functest.core import cloudify
21 from functest.opnfv_tests.vnf.router import vrouter_base
22 from functest.opnfv_tests.vnf.router.utilvnf import Utilvnf
23 from functest.utils import config
24 from functest.utils import env
25 from functest.utils import functest_utils
28 __author__ = "Shuya Nakama <shuya.nakama@okinawaopenlabs.org>"
31 class CloudifyVrouter(cloudify.Cloudify):
32 # pylint: disable=too-many-instance-attributes
33 """vrouter testcase deployed with Cloudify Orchestrator."""
35 __logger = logging.getLogger(__name__)
37 filename_alt = '/home/opnfv/functest/images/vyos-1.1.8-amd64.qcow2'
43 cop_yaml = ("https://github.com/cloudify-cosmo/cloudify-openstack-plugin/"
44 "releases/download/2.14.7/plugin.yaml")
45 cop_wgn = ("https://github.com/cloudify-cosmo/cloudify-openstack-plugin/"
46 "releases/download/2.14.7/cloudify_openstack_plugin-2.14.7-py27"
47 "-none-linux_x86_64-centos-Core.wgn")
49 def __init__(self, **kwargs):
50 if "case_name" not in kwargs:
51 kwargs["case_name"] = "vyos_vrouter"
52 super(CloudifyVrouter, self).__init__(**kwargs)
54 # Retrieve the configuration
56 self.config = getattr(
57 config.CONF, 'vnf_{}_config'.format(self.case_name))
59 raise Exception("VNF config file not found")
61 self.case_dir = pkg_resources.resource_filename(
62 'functest', 'opnfv_tests/vnf/router')
63 config_file = os.path.join(self.case_dir, self.config)
64 self.orchestrator = dict(
65 requirements=functest_utils.get_parameter_from_yaml(
66 "orchestrator.requirements", config_file),
68 self.details['orchestrator'] = dict(
69 name=functest_utils.get_parameter_from_yaml(
70 "orchestrator.name", config_file),
71 version=functest_utils.get_parameter_from_yaml(
72 "orchestrator.version", config_file),
76 self.__logger.debug("Orchestrator configuration %s", self.orchestrator)
77 self.__logger.debug("name = %s", __name__)
79 descriptor=functest_utils.get_parameter_from_yaml(
80 "vnf.descriptor", config_file),
81 inputs=functest_utils.get_parameter_from_yaml(
82 "vnf.inputs", config_file),
83 requirements=functest_utils.get_parameter_from_yaml(
84 "vnf.requirements", config_file)
86 self.details['vnf'] = dict(
87 descriptor_version=self.vnf['descriptor']['version'],
88 name=functest_utils.get_parameter_from_yaml(
89 "vnf.name", config_file),
90 version=functest_utils.get_parameter_from_yaml(
91 "vnf.version", config_file),
93 self.__logger.debug("VNF configuration: %s", self.vnf)
96 self.util.set_credentials(self.cloud)
97 credentials = {"cloud": self.cloud}
98 self.util_info = {"credentials": credentials,
99 "vnf_data_dir": self.util.vnf_data_dir}
101 self.details['test_vnf'] = dict(
102 name=functest_utils.get_parameter_from_yaml(
103 "vnf_test_suite.name", config_file),
104 version=functest_utils.get_parameter_from_yaml(
105 "vnf_test_suite.version", config_file)
107 self.images = functest_utils.get_parameter_from_yaml(
108 "tenant_images", config_file)
109 self.__logger.info("Images needed for vrouter: %s", self.images)
111 self.image_alt = None
112 self.flavor_alt = None
114 def check_requirements(self):
115 if env.get('NEW_USER_ROLE').lower() == "admin":
116 self.__logger.warning(
117 "Defining NEW_USER_ROLE=admin will easily break the testcase "
118 "because Cloudify doesn't manage tenancy (e.g. subnet "
122 # pylint: disable=too-many-locals,too-many-statements
124 Deploy Cloudify Manager.
125 network, security group, fip, VM creation
128 super(CloudifyVrouter, self).execute()
129 start_time = time.time()
130 self.put_private_key()
131 self.upload_cfy_plugins(self.cop_yaml, self.cop_wgn)
133 self.image_alt = self.publish_image_alt()
134 self.flavor_alt = self.create_flavor_alt()
136 duration = time.time() - start_time
137 self.details['orchestrator'].update(status='PASS', duration=duration)
139 self.vnf['inputs'].update(dict(
140 external_network_name=self.ext_net.name))
141 self.vnf['inputs'].update(dict(
142 target_vnf_image_id=self.image_alt.id))
143 self.vnf['inputs'].update(dict(
144 reference_vnf_image_id=self.image_alt.id))
145 self.vnf['inputs'].update(dict(
146 target_vnf_flavor_id=self.flavor_alt.id))
147 self.vnf['inputs'].update(dict(
148 reference_vnf_flavor_id=self.flavor_alt.id))
149 self.vnf['inputs'].update(dict(
150 keystone_username=self.project.user.name))
151 self.vnf['inputs'].update(dict(
152 keystone_password=self.project.password))
153 self.vnf['inputs'].update(dict(
154 keystone_tenant_name=self.project.project.name))
155 self.vnf['inputs'].update(dict(
156 keystone_user_domain_name=os.environ.get(
157 'OS_USER_DOMAIN_NAME', 'Default')))
158 self.vnf['inputs'].update(dict(
159 keystone_project_domain_name=os.environ.get(
160 'OS_PROJECT_DOMAIN_NAME', 'Default')))
161 self.vnf['inputs'].update(dict(
162 region=os.environ.get('OS_REGION_NAME', 'RegionOne')))
163 self.vnf['inputs'].update(dict(
164 keystone_url=self.get_public_auth_url(self.orig_cloud)))
166 if self.deploy_vnf() and self.test_vnf():
169 self.result = 1/3 * 100
172 def deploy_vnf(self):
173 start_time = time.time()
174 self.__logger.info("Upload VNFD")
175 descriptor = self.vnf['descriptor']
176 self.util_info["cfy"] = self.cfy_client
177 self.util_info["cfy_manager_ip"] = self.fip.floating_ip_address
178 self.util_info["deployment_name"] = descriptor.get('name')
180 self.cfy_client.blueprints.upload(
181 descriptor.get('file_name'), descriptor.get('name'))
183 self.__logger.info("Create VNF Instance")
184 self.cfy_client.deployments.create(
185 descriptor.get('name'), descriptor.get('name'),
186 self.vnf.get('inputs'))
188 cloudify.wait_for_execution(
189 self.cfy_client, cloudify.get_execution_id(
190 self.cfy_client, descriptor.get('name')),
191 self.__logger, timeout=7200)
193 self.__logger.info("Start the VNF Instance deployment")
194 execution = self.cfy_client.executions.start(
195 descriptor.get('name'), 'install')
197 execution = cloudify.wait_for_execution(
198 self.cfy_client, execution, self.__logger)
200 duration = time.time() - start_time
202 self.__logger.info(execution)
203 if execution.status == 'terminated':
204 self.details['vnf'].update(status='PASS', duration=duration)
207 self.details['vnf'].update(status='FAIL', duration=duration)
212 start_time = time.time()
213 testing = vrouter_base.VrouterOnBoardingBase(self.util, self.util_info)
214 result, test_result_data = testing.test_vnf()
215 duration = time.time() - start_time
217 self.details['test_vnf'].update(
218 status='PASS', result='OK', full_result=test_result_data,
221 self.details['test_vnf'].update(
222 status='FAIL', result='NG', full_result=test_result_data,
227 self.kill_existing_execution(self.vnf['descriptor'].get('name'))
229 self.cloud.delete_image(self.image_alt)
231 self.orig_cloud.delete_flavor(self.flavor_alt.id)
232 super(CloudifyVrouter, self).clean()