def test_create_security_group_full_existing_security_group(self): self.mock_shade_client.get_security_group.return_value = ( {'name': 'name', 'id': self._uuid}) output = openstack_utils.create_security_group_full( self.mock_shade_client, self.sg_name, self.sg_description) self.mock_shade_client.get_security_group.assert_called_once() self.assertEqual(self._uuid, output)
def test_create_security_group_full_non_existing_security_group(self): self.mock_shade_client.get_security_group.return_value = None self.mock_shade_client.create_security_group.side_effect = ( exc.OpenStackCloudException('error message')) output = openstack_utils.create_security_group_full( self.mock_shade_client, self.sg_name, self.sg_description) self.mock_log.error.assert_called_once() self.assertIsNone(output)
def test_create_security_group_full( self, mock_create_security_group_rule): self.mock_shade_client.get_security_group.return_value = None self.mock_shade_client.create_security_group.return_value = ( {'name': 'name', 'id': self._uuid}) mock_create_security_group_rule.return_value = True output = openstack_utils.create_security_group_full( self.mock_shade_client, self.sg_name, self.sg_description) mock_create_security_group_rule.assert_called() self.mock_shade_client.delete_security_group(self.sg_name) self.assertEqual(self._uuid, output)
def test_create_security_group_full_create_rule_fail( self, mock_create_security_group_rule): self.mock_shade_client.get_security_group.return_value = None self.mock_shade_client.create_security_group.return_value = ( {'name': 'name', 'id': self._uuid}) mock_create_security_group_rule.return_value = False output = openstack_utils.create_security_group_full( self.mock_shade_client, self.sg_name, self.sg_description) mock_create_security_group_rule.assert_called() self.mock_shade_client.delete_security_group(self.sg_name) self.mock_log.error.assert_called_once() self.assertIsNone(output)
def run(self, result): """execute the test""" if not self.setup_done: self.setup() sg_id = openstack_utils.create_security_group_full( self.shade_client, self.sg_name, sg_description=self.description, project_id=self.project_id) if not sg_id: result.update({"sg_create": 0}) LOG.error("Create security group failed!") raise exceptions.ScenarioCreateSecurityGroupError result.update({"sg_create": 1}) LOG.info("Create security group successful!") keys = self.scenario_cfg.get("output", '').split() values = [sg_id] return self._push_to_outputs(keys, values)
def run(self, result): """execute the test""" if not self.setup_done: self.setup() sg_id = op_utils.create_security_group_full(self.neutron_client, sg_name=self.sg_name, sg_description=self.description) if sg_id: result.update({"sg_create": 1}) LOG.info("Create security group successful!") else: result.update({"sg_create": 0}) LOG.error("Create security group failed!") try: keys = self.scenario_cfg.get('output', '').split() except KeyError: pass else: values = [sg_id] return self._push_to_outputs(keys, values)