Example #1
0
    def _test_boot_and_delete_server_with_secgroups(self):
        fake_server, sg_list = self._generate_fake_server_with_sg(2)

        scenario = security_group.BootAndDeleteServerWithSecgroups(
            self.context)
        scenario._create_security_groups = mock.MagicMock(
            return_value=sg_list)
        scenario._create_rules_for_security_group = mock.MagicMock()
        scenario._boot_server = mock.MagicMock(return_value=fake_server)
        scenario.generate_random_name = mock.MagicMock(
            return_value="name")
        scenario._delete_server = mock.MagicMock()
        scenario._delete_security_groups = mock.MagicMock()

        image = "img"
        flavor = 1
        security_group_count = 2
        rules_per_security_group = 10

        scenario.run(
            image, flavor, security_group_count, rules_per_security_group,
            fakearg="fakearg")
        scenario._create_security_groups.assert_called_once_with(
            security_group_count)
        scenario.generate_random_name.assert_called_once_with()
        scenario._create_rules_for_security_group.assert_called_once_with(
            sg_list, rules_per_security_group)
        scenario._boot_server.assert_called_once_with(
            "name", image, flavor,
            security_groups=[sg.name for sg in sg_list], fakearg="fakearg")
        fake_server.list_security_group.assert_called_once_with()
        scenario._delete_server.assert_called_once_with(fake_server)
        scenario._delete_security_groups.assert_called_once_with(sg_list)
Example #2
0
    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)

        scenario = security_group.BootAndDeleteServerWithSecgroups()
        scenario._create_security_groups = mock.MagicMock(
            return_value=fake_secgroups)
        scenario._create_rules_for_security_group = mock.MagicMock()
        scenario._boot_server = mock.MagicMock(return_value=fake_server)
        scenario.generate_random_name = mock.MagicMock(return_value="name")
        scenario._delete_server = mock.MagicMock()
        scenario._delete_security_groups = mock.MagicMock()

        image = "img"
        flavor = 1
        security_group_count = 2
        rules_per_security_group = 10

        self.assertRaises(security_group.NovaSecurityGroupException,
                          scenario.run, image, flavor, security_group_count,
                          rules_per_security_group)

        scenario._create_security_groups.assert_called_once_with(
            security_group_count)
        scenario.generate_random_name.assert_called_once_with()
        scenario._create_rules_for_security_group.assert_called_once_with(
            fake_secgroups, rules_per_security_group)
        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()
        scenario._delete_server.assert_called_once_with(fake_server)
        scenario._delete_security_groups.assert_called_once_with(
            fake_secgroups)