def setUp(self):
     super(TestNeutronSecurityGroupRulesTestCase, self).setUp()
     id1 = "11111111-1111-1111-1111-111111111111"
     sg_template1 = test_security_groups.security_group_template(security_group_rules=[], id=id1)
     id2 = "22222222-2222-2222-2222-222222222222"
     sg_template2 = test_security_groups.security_group_template(security_group_rules=[], id=id2)
     self.controller_sg = security_groups.SecurityGroupController()
     neutron = get_client()
     neutron._fake_security_groups[id1] = sg_template1
     neutron._fake_security_groups[id2] = sg_template2
    def test_show(self):
        def fake_get_instance_security_groups(inst, context, id):
            return [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]

        self.stubs.Set(neutron_driver.SecurityGroupAPI,
                       'get_instance_security_groups',
                       fake_get_instance_security_groups)

        url = '/v2/fake/servers'
        image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups')
        security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]
        for security_group in security_groups:
            sg = test_security_groups.security_group_template(
                name=security_group['name'])
            self.controller.create(req, {'security_group': sg})
        server = dict(name='server_test', imageRef=image_uuid, flavorRef=2,
                      security_groups=security_groups)

        res = self._make_request(url, {'server': server})
        self.assertEqual(res.status_int, 202)
        server = self._get_server(res.body)
        for i, group in enumerate(self._get_groups(server)):
            name = 'fake-2-%s' % i
            self.assertEqual(group.get('name'), name)

        # Test that show (GET) returns the same information as create (POST)
        url = '/v2/fake/servers/' + test_security_groups.UUID3
        res = self._make_request(url)
        self.assertEqual(res.status_int, 200)
        server = self._get_server(res.body)

        for i, group in enumerate(self._get_groups(server)):
            name = 'fake-2-%s' % i
            self.assertEqual(group.get('name'), name)
    def test_show(self):
        def fake_get_instance_security_groups(inst, context, id):
            return [{"name": "fake-2-0"}, {"name": "fake-2-1"}]

        self.stubs.Set(
            neutron_driver.SecurityGroupAPI, "get_instance_security_groups", fake_get_instance_security_groups
        )

        url = "/v2/fake/servers"
        image_uuid = "c905cedb-7281-47e4-8a62-f26bc5fc4c77"
        req = fakes.HTTPRequest.blank("/v2/fake/os-security-groups")
        security_groups = [{"name": "fake-2-0"}, {"name": "fake-2-1"}]
        for security_group in security_groups:
            sg = test_security_groups.security_group_template(name=security_group["name"])
            self.controller.create(req, {"security_group": sg})
        server = dict(name="server_test", imageRef=image_uuid, flavorRef=2, security_groups=security_groups)

        res = self._make_request(url, {"server": server})
        self.assertEqual(res.status_int, 202)
        server = self._get_server(res.body)
        for i, group in enumerate(self._get_groups(server)):
            name = "fake-2-%s" % i
            self.assertEqual(group.get("name"), name)

        # Test that show (GET) returns the same information as create (POST)
        url = "/v2/fake/servers/" + test_security_groups.UUID3
        res = self._make_request(url)
        self.assertEqual(res.status_int, 200)
        server = self._get_server(res.body)

        for i, group in enumerate(self._get_groups(server)):
            name = "fake-2-%s" % i
            self.assertEqual(group.get("name"), name)
 def test_create_add_existing_rules_by_group_id(self):
     sg = test_security_groups.security_group_template()
     req = fakes.HTTPRequest.blank("/v2/fake/os-security-groups")
     self.controller_sg.create(req, {"security_group": sg})
     rule = test_security_groups.security_group_rule_template(group=self.sg1["id"], parent_group_id=self.sg2["id"])
     req = fakes.HTTPRequest.blank("/v2/fake/os-security-group-rules")
     self.controller.create(req, {"security_group_rule": rule})
     self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, {"security_group_rule": rule})
 def test_create_add_existing_rules_by_cidr(self):
     sg = test_security_groups.security_group_template()
     req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups')
     self.controller_sg.create(req, {'security_group': sg})
     rule = test_security_groups.security_group_rule_template(
         cidr='15.0.0.0/8', parent_group_id=self.sg2['id'])
     req = fakes.HTTPRequest.blank('/v2/fake/os-security-group-rules')
     self.controller.create(req, {'security_group_rule': rule})
     self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
                       req, {'security_group_rule': rule})
Exemple #6
0
 def test_create_add_existing_rules_by_group_id(self):
     sg = test_security_groups.security_group_template()
     req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups')
     self.controller_sg.create(req, {'security_group': sg})
     rule = test_security_groups.security_group_rule_template(
         group=self.sg1['id'], parent_group_id=self.sg2['id'])
     req = fakes.HTTPRequest.blank('/v2/fake/os-security-group-rules')
     self.controller.create(req, {'security_group_rule': rule})
     self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
                       req, {'security_group_rule': rule})
Exemple #7
0
 def test_create_add_existing_rules_by_cidr(self):
     sg = test_security_groups.security_group_template()
     req = fakes.HTTPRequest.blank('/v2/%s/os-security-groups' %
                                   fakes.FAKE_PROJECT_ID)
     self.controller_sg.create(req, {'security_group': sg})
     rule = test_security_groups.security_group_rule_template(
         cidr='15.0.0.0/8', parent_group_id=self.sg2['id'])
     req = fakes.HTTPRequest.blank('/v2/%s/os-security-group-rules' %
                                   fakes.FAKE_PROJECT_ID)
     self.controller.create(req, {'security_group_rule': rule})
     self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create,
                       req, {'security_group_rule': rule})
    def test_create(self):
        url = "/v2/fake/servers"
        image_uuid = "c905cedb-7281-47e4-8a62-f26bc5fc4c77"
        req = fakes.HTTPRequest.blank("/v2/fake/os-security-groups")
        security_groups = [{"name": "fake-2-0"}, {"name": "fake-2-1"}]
        for security_group in security_groups:
            sg = test_security_groups.security_group_template(name=security_group["name"])
            self.controller.create(req, {"security_group": sg})

        server = dict(name="server_test", imageRef=image_uuid, flavorRef=2, security_groups=security_groups)
        res = self._make_request(url, {"server": server})
        self.assertEqual(res.status_int, 202)
        server = self._get_server(res.body)
        for i, group in enumerate(self._get_groups(server)):
            name = "fake-2-%s" % i
            self.assertEqual(group.get("name"), name)
    def test_create(self):
        url = '/v2/fake/servers'
        image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups')
        security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]
        for security_group in security_groups:
            sg = test_security_groups.security_group_template(
                name=security_group['name'])
            self.controller.create(req, {'security_group': sg})

        server = dict(name='server_test', imageRef=image_uuid, flavorRef=2,
                      security_groups=security_groups)
        res = self._make_request(url, {'server': server})
        self.assertEqual(res.status_int, 202)
        server = self._get_server(res.body)
        for i, group in enumerate(self._get_groups(server)):
            name = 'fake-2-%s' % i
            self.assertEqual(group.get('name'), name)
    def test_create(self):
        url = '/v2/fake/servers'
        image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups')
        security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]
        for security_group in security_groups:
            sg = test_security_groups.security_group_template(
                name=security_group['name'])
            self.controller.create(req, {'security_group': sg})

        server = dict(name='server_test', imageRef=image_uuid, flavorRef=2,
                      security_groups=security_groups)
        res = self._make_request(url, {'server': server})
        self.assertEqual(res.status_int, 202)
        server = self._get_server(res.body)
        for i, group in enumerate(self._get_groups(server)):
            name = 'fake-2-%s' % i
            self.assertEqual(group.get('name'), name)
Exemple #11
0
    def test_show(self):
        self.stub_out(
            'nova.network.security_group.neutron_driver.'
            'SecurityGroupAPI.get_instance_security_groups',
            lambda self, inst, context, id: [{
                'name': 'fake-2-0'
            }, {
                'name': 'fake-2-1'
            }])

        url = '/v2/%s/servers' % fakes.FAKE_PROJECT_ID
        image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        req = fakes.HTTPRequest.blank('/v2/%s/os-security-groups' %
                                      fakes.FAKE_PROJECT_ID)
        security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]
        for security_group in security_groups:
            sg = test_security_groups.security_group_template(
                name=security_group['name'])
            self.controller.create(req, {'security_group': sg})
        server = dict(name='server_test',
                      imageRef=image_uuid,
                      flavorRef=2,
                      security_groups=security_groups)

        res = self._make_request(url, {'server': server})
        self.assertEqual(res.status_int, 202)
        server = self._get_server(res.body)
        for i, group in enumerate(self._get_groups(server)):
            name = 'fake-2-%s' % i
            self.assertEqual(group.get('name'), name)

        # Test that show (GET) returns the same information as create (POST)
        url = ('/v2/%s/servers/%s' %
               (fakes.FAKE_PROJECT_ID, test_security_groups.UUID3))
        res = self._make_request(url)
        self.assertEqual(res.status_int, 200)
        server = self._get_server(res.body)

        for i, group in enumerate(self._get_groups(server)):
            name = 'fake-2-%s' % i
            self.assertEqual(group.get('name'), name)
    def test_show(self):
        def fake_get_instance_security_groups(inst, context, id):
            return [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]

        self.stubs.Set(neutron_driver.SecurityGroupAPI,
                       'get_instance_security_groups',
                       fake_get_instance_security_groups)

        url = '/v2/fake/servers'
        image_uuid = 'c905cedb-7281-47e4-8a62-f26bc5fc4c77'
        req = fakes.HTTPRequest.blank('/v2/fake/os-security-groups')
        security_groups = [{'name': 'fake-2-0'}, {'name': 'fake-2-1'}]
        for security_group in security_groups:
            sg = test_security_groups.security_group_template(
                name=security_group['name'])
            self.controller.create(req, {'security_group': sg})
        server = dict(name='server_test',
                      imageRef=image_uuid,
                      flavorRef=2,
                      security_groups=security_groups)

        res = self._make_request(url, {'server': server})
        self.assertEqual(res.status_int, 202)
        server = self._get_server(res.body)
        for i, group in enumerate(self._get_groups(server)):
            name = 'fake-2-%s' % i
            self.assertEqual(group.get('name'), name)

        # Test that show (GET) returns the same information as create (POST)
        url = '/v2/fake/servers/' + test_security_groups.UUID3
        res = self._make_request(url)
        self.assertEqual(res.status_int, 200)
        server = self._get_server(res.body)

        for i, group in enumerate(self._get_groups(server)):
            name = 'fake-2-%s' % i
            self.assertEqual(group.get('name'), name)