Exemple #1
0
    def test__prepare_open_secgroup(self, mock_osclients):
        fake_nova = fakes.FakeNovaClient()
        self.assertEqual(len(fake_nova.security_groups.list()), 1)
        mock_cl = mock.MagicMock()
        mock_cl.nova.return_value = fake_nova
        mock_osclients.return_value = mock_cl

        ret = secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)
        self.assertEqual(self.secgroup_name, ret["name"])

        self.assertEqual(2, len(fake_nova.security_groups.list()))
        self.assertIn(
            self.secgroup_name,
            [sg.name for sg in fake_nova.security_groups.list()])

        # run prep again, check that another security group is not created
        secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)
        self.assertEqual(2, len(fake_nova.security_groups.list()))
Exemple #2
0
    def test__prepare_open_secgroup(self, mock_clients):
        fake_nova = fakes.FakeNovaClient()
        self.assertEqual(len(fake_nova.security_groups.list()), 1)
        mock_cl = mock.MagicMock()
        mock_cl.nova.return_value = fake_nova
        mock_clients.return_value = mock_cl

        ret = secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)
        self.assertEqual(self.secgroup_name, ret["name"])

        self.assertEqual(2, len(fake_nova.security_groups.list()))
        self.assertIn(
            self.secgroup_name,
            [sg.name for sg in fake_nova.security_groups.list()])

        # run prep again, check that another security group is not created
        secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)
        self.assertEqual(2, len(fake_nova.security_groups.list()))
Exemple #3
0
    def test__prepare_open_secgroup_rules(self, mock_osclients):
        fake_nova = fakes.FakeNovaClient()

        # NOTE(hughsaunders) Default security group is precreated
        self.assertEqual(1, len(fake_nova.security_groups.list()))
        mock_cl = mock.MagicMock()
        mock_cl.nova.return_value = fake_nova
        mock_osclients.return_value = mock_cl

        secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)

        self.assertEqual(2, len(fake_nova.security_groups.list()))
        rally_open = fake_nova.security_groups.find(self.secgroup_name)
        self.assertEqual(3, len(rally_open.rules))

        # run prep again, check that extra rules are not created
        secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)
        rally_open = fake_nova.security_groups.find(self.secgroup_name)
        self.assertEqual(3, len(rally_open.rules))
Exemple #4
0
    def test__prepare_open_secgroup_rules(self, mock_clients):
        fake_nova = fakes.FakeNovaClient()

        # NOTE(hughsaunders) Default security group is precreated
        self.assertEqual(1, len(fake_nova.security_groups.list()))
        mock_cl = mock.MagicMock()
        mock_cl.nova.return_value = fake_nova
        mock_clients.return_value = mock_cl

        secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)

        self.assertEqual(2, len(fake_nova.security_groups.list()))
        rally_open = fake_nova.security_groups.find(self.secgroup_name)
        self.assertEqual(3, len(rally_open.rules))

        # run prep again, check that extra rules are not created
        secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)
        rally_open = fake_nova.security_groups.find(self.secgroup_name)
        self.assertEqual(3, len(rally_open.rules))