예제 #1
0
    def test_boot_server_and_add_secgroups(self):
        fake_secgroups = [
            fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
            fakes.FakeSecurityGroup(None, None, 2, "uuid2")
        ]

        nova_scenario = security_group.BootServerAndAddSecgroups(self.context)
        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()
        nova_scenario.add_server_secgroup = mock.MagicMock()

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

        nova_scenario.run(image,
                          flavor,
                          security_group_count,
                          rules_per_security_group,
                          fakearg="fakearg")

        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._boot_server.assert_called_once_with(image,
                                                           flavor,
                                                           fakearg="fakearg")
예제 #2
0
 def test__update_security_groups(self):
     nova_scenario = utils.NovaScenario(context=self.context)
     fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
                       fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
     nova_scenario._update_security_groups(fake_secgroups)
     self.assertEqual(
         len(fake_secgroups),
         self.clients("nova").security_groups.update.call_count)
     self._test_atomic_action_timer(
         nova_scenario.atomic_actions(),
         "nova.update_%s_security_groups" % len(fake_secgroups))
예제 #3
0
    def test__delete_security_groups(self):
        nova_scenario = utils.NovaScenario(context=self.context)

        fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
                          fakes.FakeSecurityGroup(None, None, 2, "uuid2")]

        nova_scenario._delete_security_groups(fake_secgroups)

        self.assertSequenceEqual(
            map(lambda x: mock.call(x.id), fake_secgroups),
            self.clients("nova").security_groups.delete.call_args_list)
        self._test_atomic_action_timer(
            nova_scenario.atomic_actions(),
            "nova.delete_%s_security_groups" % len(fake_secgroups))
예제 #4
0
    def test_create_and_list_secgroups(self):
        fake_secgroups = [
            fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
            fakes.FakeSecurityGroup(None, None, 2, "uuid2")
        ]

        scenario = security_group.CreateAndListSecgroups(self.context)

        scenario._create_security_groups = mock.MagicMock()
        scenario._create_rules_for_security_group = mock.MagicMock()
        scenario._list_security_groups = mock.MagicMock()

        scenario._list_security_groups.return_value = fake_secgroups
        scenario._list_security_groups.return_value.append(
            fakes.FakeSecurityGroup(None, None, 3, "uuid3"))
        scenario._list_security_groups.return_value.append(
            fakes.FakeSecurityGroup(None, None, 4, "uuid4"))

        security_group_count = 2
        rules_per_security_group = 10

        # Positive case:
        scenario._create_security_groups.return_value = fake_secgroups
        scenario.run(security_group_count, rules_per_security_group)

        scenario._create_security_groups.assert_called_once_with(
            security_group_count)
        scenario._create_rules_for_security_group.assert_called_once_with(
            fake_secgroups, rules_per_security_group)
        scenario._list_security_groups.assert_called_once_with()

        # Negative case1: groups aren't created
        scenario._create_security_groups.return_value = None
        self.assertRaises(exceptions.RallyAssertionError, scenario.run,
                          security_group_count, rules_per_security_group)
        scenario._create_security_groups.assert_called_with(
            security_group_count)

        # Negative case2: new groups are not present in the list of groups
        fake_secgroups = [fakes.FakeSecurityGroup(None, None, 6, "uuid6")]
        scenario._create_security_groups.return_value = fake_secgroups
        scenario._create_rules_for_security_group = mock.MagicMock()
        self.assertRaises(exceptions.RallyAssertionError, scenario.run,
                          security_group_count, rules_per_security_group)
        scenario._create_security_groups.assert_called_with(
            security_group_count)
        scenario._create_rules_for_security_group.assert_called_with(
            fake_secgroups, rules_per_security_group)
        scenario._list_security_groups.assert_called_with()
 def test_create_and_update_security_groups(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._update_security_groups = mock.MagicMock()
     nova_scenario._generate_random_name = mock.Mock(
         return_value="_updated")
     security_group_count = 2
     nova_scenario.create_and_update_secgroups(security_group_count)
     nova_scenario._create_security_groups.assert_called_once_with(
         security_group_count)
     nova_scenario._update_security_groups.assert_called_once_with(
         fake_secgroups)
예제 #6
0
 def test_create_and_update_security_groups(self):
     fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
                       fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
     scenario = security_group.CreateAndUpdateSecgroups(self.context)
     scenario._create_security_groups = mock.MagicMock(
         return_value=fake_secgroups)
     scenario._update_security_groups = mock.MagicMock()
     scenario._generate_random_name = mock.Mock(
         return_value="_updated")
     security_group_count = 2
     scenario.run(security_group_count)
     scenario._create_security_groups.assert_called_once_with(
         security_group_count)
     scenario._update_security_groups.assert_called_once_with(
         fake_secgroups)
예제 #7
0
    def _generate_fake_server_with_sg(self, number_of_secgroups):
        sg_list = []
        for i in range(number_of_secgroups):
            sg_list.append(
                fakes.FakeSecurityGroup(None, None, i, "uuid%s" % i))

        return mock.MagicMock(
            list_security_group=mock.MagicMock(return_value=sg_list)), sg_list
예제 #8
0
    def test__create_rules_for_security_group(self):
        nova_scenario = utils.NovaScenario(context=self.context)

        fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
                          fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
        rules_per_security_group = 10

        nova_scenario._create_rules_for_security_group(
            fake_secgroups, rules_per_security_group)

        self.assertEqual(
            len(fake_secgroups) * rules_per_security_group,
            self.clients("nova").security_group_rules.create.call_count)
        self._test_atomic_action_timer(
            nova_scenario.atomic_actions(),
            "nova.create_%s_rules" %
            (rules_per_security_group * len(fake_secgroups)))
예제 #9
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)

        nova_scenario = security_group.NovaSecGroup(self.context)
        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)
        nova_scenario.generate_random_name.assert_called_once_with()
        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)
예제 #10
0
    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()
예제 #11
0
    def test__delete_security_groups(self):
        clients = mock.MagicMock()
        nova_scenario = utils.NovaScenario()
        nova_scenario.clients = clients

        fake_secgroups = [
            fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
            fakes.FakeSecurityGroup(None, None, 2, "uuid2")
        ]

        nova_scenario._delete_security_groups(fake_secgroups)

        self.assertEqual(len(fake_secgroups), clients.call_count)

        self.assertSequenceEqual(
            map(lambda x: mock.call(x.id), fake_secgroups),
            clients().security_groups.delete.call_args_list)
        self._test_atomic_action_timer(
            nova_scenario.atomic_actions(),
            "nova.delete_%s_security_groups" % len(fake_secgroups))
예제 #12
0
    def test_create_and_list_secgroups(self):
        fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
                          fakes.FakeSecurityGroup(None, None, 2, "uuid2")]

        scenario = security_group.CreateAndListSecgroups(self.context)
        scenario._create_security_groups = mock.MagicMock(
            return_value=fake_secgroups)
        scenario._create_rules_for_security_group = mock.MagicMock()
        scenario._list_security_groups = mock.MagicMock()

        security_group_count = 2
        rules_per_security_group = 10
        scenario.run(
            security_group_count, rules_per_security_group)

        scenario._create_security_groups.assert_called_once_with(
            security_group_count)
        scenario._create_rules_for_security_group.assert_called_once_with(
            fake_secgroups, rules_per_security_group)
        scenario._list_security_groups.assert_called_once_with()