diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/base.py b/whitebox_neutron_tempest_plugin/tests/scenario/base.py index 1488867..61fa5d5 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/base.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/base.py @@ -817,7 +817,8 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): ssh_client=None, ret_bool_status=False, ret_bool_pattern=False, - local_shell=False): + local_shell=False, + force_bash=False): """Run a command on a given host (default: host supporting OSP CLI). Optional: validation of output by regex, and exit status. @@ -844,6 +845,12 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): Without any boolean option, returns all output. :type ret_bool_status: bool, optional + :param force_bash: Force bash use with command (Default False). + Certain commands failed without it in the past, + ex: `oc rsh` use fails with a few commands. + False value allows double quotes flexibility. + :type force_bash: bool, optional + :returns: all output of command as str, or boolean if either of return boolean options is True (ret_bool_pattern or ret_bool_status). """ @@ -863,19 +870,22 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): username=WB_CONF.tester_user, password=WB_CONF.tester_pass, key_filename=WB_CONF.tester_key_file) - + if force_bash: + _cmd = 'bash -c "' + cmd + '"' + else: + _cmd = cmd # verify command success using exception try: result = shell.execute( - cmd, timeout=timeout, check=(not ret_bool_status), + _cmd, timeout=timeout, check=(not ret_bool_status), ssh_client=ssh_client) except exceptions.ShellCommandFailed: LOG.exception( - 'Tested command failed (raising error) -> "%s":', cmd) + 'Tested command failed (raising error) -> "%s":', _cmd) # verify command success using boolean if ret_bool_status and result.exit_status != 0: LOG.debug( - 'Tested command failed (returning False) -> "%s":', cmd) + 'Tested command failed (returning False) -> "%s":', _cmd) return False # verify desired output using exception/boolean all_output = (result.stderr if result.stderr else '') + \ @@ -884,7 +894,7 @@ class BaseTempestWhiteboxTestCase(base.BaseTempestTestCase): fail_msg = 'Pattern "{}" not found in output of "{}" command.' try: if not re.search(pattern, all_output): - raise AssertionError(fail_msg.format(pattern, cmd)) + raise AssertionError(fail_msg.format(pattern, _cmd)) except AssertionError as err: if ret_bool_pattern: return False diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/test_ports.py b/whitebox_neutron_tempest_plugin/tests/scenario/test_ports.py index 7e4a900..391200f 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_ports.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_ports.py @@ -142,3 +142,43 @@ class NetworkPortTestManyVmsOvn(NetworkPortTestManyVmsBase, def test_port_status_when_many_vms_ovn(self): self.opt = "--no-leader-only" self._test_port_status_when_many_vms() + + +class PortListLongOptSGsCmd(base.BaseTempestWhiteboxTestCase): + """Test class verifies BZ#2214566/OSPRH-13533 doesn't regress: + "openstack port list --long" output has correct related security group. + + Test class may also verify OSPRH-14118 (LP#2098980) when fixed. + """ + credentials = ['primary', 'admin'] + + @classmethod + def resource_setup(cls): + super(PortListLongOptSGsCmd, cls).resource_setup() + cls.secgroup = cls.create_security_group( + name=data_utils.rand_name('port-list-sgs-test-secgroup')) + cls.security_groups.append(cls.secgroup) + network = cls.create_network( + name=data_utils.rand_name('port-list-sgs-test-network')) + cls.create_subnet( + network, + name=data_utils.rand_name('port-list-sgs-test-secgroup')) + cls.vm_kwargs = { + 'flavor_ref': cls.flavor_ref, + 'image_ref': cls.image_ref, + 'key_name': cls.create_keypair()['name'], + 'networks': [{'uuid': network['id']}], + 'security_groups': [{'name': cls.secgroup['name']}], + 'name': data_utils.rand_name('port-list-sgs-test-vm')} + + @decorators.idempotent_id('9b33caa4-62a8-49a6-b661-ecbdc520df8c') + def test_port_list_long_opt_sgs_cmd(self): + vm = self.create_server(**self.vm_kwargs)['server'] + prefix = self.get_osp_cmd_prefix() + # TODO(mblue): add test for OSPRH-14118 (LP#2098980) when fixed + cmd = ("{}openstack port list --server {} --long -c 'Security Groups'" + ).format(prefix, vm['id']) + # validates correct security group uuid in output + self.validate_command(cmd, + self.secgroup['id'], + force_bash=True) diff --git a/whitebox_neutron_tempest_plugin/tests/scenario/test_security_group_logging.py b/whitebox_neutron_tempest_plugin/tests/scenario/test_security_group_logging.py index 494cbbf..b11def8 100644 --- a/whitebox_neutron_tempest_plugin/tests/scenario/test_security_group_logging.py +++ b/whitebox_neutron_tempest_plugin/tests/scenario/test_security_group_logging.py @@ -431,8 +431,9 @@ class BaseSecGroupLoggingTest( cmds.pop(0) stdout_patterns.pop(0) for cmd, ptn in zip(cmds, stdout_patterns): - self.validate_command( - 'bash -c "' + prefix + cmd + '"', ptn) + self.validate_command(prefix + cmd, + ptn, + force_bash=True) def _test_only_dropped_traffic_logged(self): """This scenario verifies that only the log entries of dropped traffic