def _test_boot_and_delete_server_with_secgroups(self): fake_server, sg_list = self._generate_fake_server_with_sg(2) nova_scenario = security_group.NovaSecGroup() nova_scenario._create_security_groups = mock.MagicMock( return_value=sg_list) nova_scenario._create_rules_for_security_group = mock.MagicMock() nova_scenario._boot_server = mock.MagicMock(return_value=fake_server) nova_scenario._generate_random_name = mock.MagicMock( return_value="name") nova_scenario._delete_server = mock.MagicMock() nova_scenario._delete_security_groups = mock.MagicMock() image = "img" flavor = 1 security_group_count = 2 rules_per_security_group = 10 nova_scenario.boot_and_delete_server_with_secgroups( image, flavor, security_group_count, rules_per_security_group) nova_scenario._create_security_groups.assert_called_once_with( security_group_count) self.assertEqual(1, nova_scenario._generate_random_name.call_count) nova_scenario._create_rules_for_security_group.assert_called_once_with( sg_list, rules_per_security_group) nova_scenario._boot_server.assert_called_once_with( "name", image, flavor, security_groups=[sg.name for sg in sg_list]) fake_server.list_security_group.assert_called_once_with() nova_scenario._delete_server.assert_called_once_with(fake_server) nova_scenario._delete_security_groups.assert_called_once_with(sg_list)
def test_create_and_list_secgroups(self): fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"), fakes.FakeSecurityGroup(None, None, 2, "uuid2")] nova_scenario = security_group.NovaSecGroup() nova_scenario._create_security_groups = mock.MagicMock( return_value=fake_secgroups) nova_scenario._create_rules_for_security_group = mock.MagicMock() nova_scenario._list_security_groups = mock.MagicMock() security_group_count = 2 rules_per_security_group = 10 nova_scenario.create_and_list_secgroups( security_group_count, rules_per_security_group) nova_scenario._create_security_groups.assert_called_once_with( security_group_count) nova_scenario._create_rules_for_security_group.assert_called_once_with( fake_secgroups, rules_per_security_group) nova_scenario._list_security_groups.assert_called_once_with()
def _test_boot_and_delete_server_with_sg_not_attached(self): fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"), fakes.FakeSecurityGroup(None, None, 2, "uuid2")] fake_server, sg_list = self._generate_fake_server_with_sg(1) nova_scenario = security_group.NovaSecGroup() nova_scenario._create_security_groups = mock.MagicMock( return_value=fake_secgroups) nova_scenario._create_rules_for_security_group = mock.MagicMock() nova_scenario._boot_server = mock.MagicMock(return_value=fake_server) nova_scenario._generate_random_name = mock.MagicMock( return_value="name") nova_scenario._delete_server = mock.MagicMock() nova_scenario._delete_security_groups = mock.MagicMock() image = "img" flavor = 1 security_group_count = 2 rules_per_security_group = 10 self.assertRaises(security_group.NovaSecurityGroupException, nova_scenario.boot_and_delete_server_with_secgroups, image, flavor, security_group_count, rules_per_security_group) nova_scenario._create_security_groups.assert_called_once_with( security_group_count) self.assertEqual(1, nova_scenario._generate_random_name.call_count) nova_scenario._create_rules_for_security_group.assert_called_once_with( fake_secgroups, rules_per_security_group) nova_scenario._boot_server.assert_called_once_with( "name", image, flavor, security_groups=[sg.name for sg in fake_secgroups]) fake_server.list_security_group.assert_called_once_with() nova_scenario._delete_server.assert_called_once_with(fake_server) nova_scenario._delete_security_groups.assert_called_once_with( fake_secgroups)