From fc8f7d2b180ded441f84accb0ed17c633d130822 Mon Sep 17 00:00:00 2001 From: dharmendra Date: Thu, 27 Jun 2019 09:39:55 +0000 Subject: [PATCH] FT to check SSH access after VNF is created. Adding functional test case for cmd_executer.py to check SSH access after VNF is created. Closes-Bug:#1592235 Change-Id: I4e5e677aad59fc3fe6ea37ef339044b10e5792da --- tacker/tests/functional/common/__init__.py | 0 .../functional/common/test_cmd_executer.py | 82 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 tacker/tests/functional/common/__init__.py create mode 100644 tacker/tests/functional/common/test_cmd_executer.py diff --git a/tacker/tests/functional/common/__init__.py b/tacker/tests/functional/common/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tacker/tests/functional/common/test_cmd_executer.py b/tacker/tests/functional/common/test_cmd_executer.py new file mode 100644 index 000000000..8c98738d0 --- /dev/null +++ b/tacker/tests/functional/common/test_cmd_executer.py @@ -0,0 +1,82 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import yaml + +from oslo_config import cfg + +from tacker.common import cmd_executer +from tacker.plugins.common import constants as evt_constants +from tacker.tests import constants +from tacker.tests.functional import base +from tacker.tests.utils import read_file + + +CONF = cfg.CONF +VNF_CIRROS_CREATE_TIMEOUT = 120 + + +class TestRemoteCommandExecutor(base.BaseTackerTest): + + def _test_create_vnf(self, vnfd_file, vnf_name): + input_yaml = read_file(vnfd_file) + tosca_dict = yaml.safe_load(input_yaml) + + # create vnf directly from template + vnf_arg = {'vnf': {'vnfd_template': tosca_dict, 'name': vnf_name}} + vnf_instance = self.client.create_vnf(body=vnf_arg) + vnf_id = vnf_instance['vnf']['id'] + self.wait_until_vnf_active( + vnf_id, + constants.VNF_CIRROS_CREATE_TIMEOUT, + constants.ACTIVE_SLEEP_TIME) + vnf_show_out = self.client.show_vnf(vnf_id)['vnf'] + self.assertIsNotNone(vnf_show_out['mgmt_ip_address']) + + # Fetch mgmt ip of VNF + mgmt_ip = eval(vnf_show_out['mgmt_ip_address'])['VDU1'] + + return vnf_id, mgmt_ip + + def _test_cmd_executor(self, vnfd_file, vnf_name): + vnf_id, mgmt_ip = self._test_create_vnf(vnfd_file, vnf_name) + + # Login on VNF instance, and execute 'hostname' command to verify + # connection and command output. + usr = 'cirros' + psswrd = 'gocubsgo' + cmd = 'hostname' + rcmd_executor = cmd_executer.RemoteCommandExecutor(user=usr, + password=psswrd, + host=mgmt_ip) + result = rcmd_executor.execute_command(cmd) + self.assertEqual(cmd, result.get_command()) + self.assertEqual(0, result.get_return_code()) + self.assertIn('test-vdu', result.get_stdout()[0]) + + self._test_delete_vnf(vnf_id) + + def _test_delete_vnf(self, vnf_id): + # Delete vnf_instance with vnf_id + try: + self.client.delete_vnf(vnf_id) + except Exception: + assert False, "vnf Delete failed" + + self.wait_until_vnf_delete(vnf_id, + constants.VNF_CIRROS_DELETE_TIMEOUT) + self.verify_vnf_crud_events(vnf_id, evt_constants.RES_EVT_DELETE, + evt_constants.PENDING_DELETE, cnt=2) + + def test_cmd_executor(self): + self._test_cmd_executor('sample-tosca-vnfd.yaml', + 'test_tosca_vnf_with_cirros_inline')