def test_list_works(self):
        tenants = (
            doubles.make(self.mox, doubles.Tenant, name='t1', id=u'PID1'),
            doubles.make(self.mox, doubles.Tenant, name='systenant', id=u'S'),
            doubles.make(self.mox, doubles.Tenant, name='t2', id=u'PID2'))

        self.fake_client_set.identity_admin.tenants.list().AndReturn(tenants)

        tcs1 = mock_client_set(self.mox)
        fw_rule_sets.client_set_for_tenant(u'PID1', fallback_to_api=True) \
                .AndReturn(tcs1)
        tcs1.compute.security_groups.list().AndReturn(['SG1', 'SG2'])
        fw_rule_sets._sg_to_view('SG1', tenants[0].name).AndReturn('REPLY1')
        fw_rule_sets._sg_to_view('SG2', tenants[0].name).AndReturn('REPLY2')

        tcs2 = mock_client_set(self.mox)
        fw_rule_sets.client_set_for_tenant(u'PID2', fallback_to_api=True) \
                .AndReturn(tcs2)
        tcs2.compute.security_groups.list().AndReturn(['SG3'])
        fw_rule_sets._sg_to_view('SG3', tenants[2].name).AndReturn('REPLY3')

        expected = {
            'collection': {
                'name': 'fw-rule-sets',
                'size': 3
            },
            'fw-rule-sets': ['REPLY1', 'REPLY2', 'REPLY3']
        }

        self.mox.ReplayAll()
        rv = self.client.get('/v1/fw-rule-sets/')
        data = self.check_and_parse_response(rv)
        self.assertEquals(data, expected)
Esempio n. 2
0
    def test_list_for_project(self):
        tcs = mock_client_set(self.mox)
        tenant = self.tenants[1]

        self.fake_client_set.identity_admin.tenants.get(tenant.id)\
                .AndReturn(tenant)
        images.auth.client_set_for_tenant(tenant.id, fallback_to_api=True) \
                .AndReturn(tcs)
        tcs.image.images.list(filters={'is_public': None}) \
                .AndReturn(['ii1', 'ii2'])
        images._image_to_view('ii1', self.tenants[0]).AndReturn('I1')
        images._image_to_view('ii2', self.tenants[1]).AndReturn('I2')

        expected = {
            u'collection': {
                u'name': u'images',
                u'size': 2
            },
            u'images': [ 'I1', 'I2' ]
        }

        self.mox.ReplayAll()
        rv = self.client.get(u'/v1/images/?project:for=%s' % tenant.id)
        data = self.check_and_parse_response(rv)
        self.assertEquals(data, expected)
    def test_list_works(self):
        tenants = (doubles.make(self.mox,
                                doubles.Tenant,
                                name='t1',
                                id=u'PID1'),
                   doubles.make(self.mox,
                                doubles.Tenant,
                                name='systenant',
                                id=u'S'),
                   doubles.make(self.mox,
                                doubles.Tenant,
                                name='t2',
                                id=u'PID2'))

        self.fake_client_set.identity_admin.tenants.list().AndReturn(tenants)

        tcs1 = mock_client_set(self.mox)
        fw_rule_sets.client_set_for_tenant(u'PID1', fallback_to_api=True) \
                .AndReturn(tcs1)
        tcs1.compute.security_groups.list().AndReturn(['SG1', 'SG2'])
        fw_rule_sets._sg_to_view('SG1', tenants[0].name).AndReturn('REPLY1')
        fw_rule_sets._sg_to_view('SG2', tenants[0].name).AndReturn('REPLY2')

        tcs2 = mock_client_set(self.mox)
        fw_rule_sets.client_set_for_tenant(u'PID2', fallback_to_api=True) \
                .AndReturn(tcs2)
        tcs2.compute.security_groups.list().AndReturn(['SG3'])
        fw_rule_sets._sg_to_view('SG3', tenants[2].name).AndReturn('REPLY3')

        expected = {
            'collection': {
                'name': 'fw-rule-sets',
                'size': 3
            },
            'fw-rule-sets': ['REPLY1', 'REPLY2', 'REPLY3']
        }

        self.mox.ReplayAll()
        rv = self.client.get('/v1/fw-rule-sets/')
        data = self.check_and_parse_response(rv)
        self.assertEquals(data, expected)
Esempio n. 4
0
    def test_list_for_project(self):
        tcs = mock_client_set(self.mox)

        self.fake_client_set.identity_admin.tenants.get(self.tenant.id).AndReturn(self.tenant)
        images.auth.client_set_for_tenant(self.tenant.id, fallback_to_api=False).AndReturn(tcs)
        tcs.image.images.list(filters={"is_public": None}).AndReturn(["ii1"])
        images._image_to_view("ii1", self.tenant).AndReturn("I1")

        self.mox.ReplayAll()
        rv = self.client.get(u"/v1/images/?project:for=%s" % self.tenant.id)
        data = self.check_and_parse_response(rv)
        self.assertEquals(data.get("images"), ["I1"])
 def setUp(self):
     super(RemoveFwRuleSetFromVMTestCase, self).setUp()
     self.mox.StubOutWithMock(ifwrs, 'link_for_security_group')
     self.mox.StubOutWithMock(ifwrs, 'client_set_for_tenant')
     self.mox.StubOutWithMock(ifwrs,
                              'assert_admin_or_project_user')
     self.server = doubles.make(self.mox, doubles.Server,
                                id=u'VMID', name=u'ExampleVM',
                                tenant_id=u'FWPROJECT')
     self.sg = doubles.make(self.mox, doubles.SecurityGroup,
                            id=2, name=u'ExampleSG',
                            tenant_id=u'FWPROJECT')
     self.tcs = mock_client_set(self.mox)
     self.sg_id = unicode(self.sg.id)
    def test_add_failure(self):
        compute = self.fake_client_set.compute
        tcs = mock_client_set(self.mox)

        compute.servers.get(self.server.id).AndReturn(self.server)
        compute.security_groups.get(self.sg_id).AndReturn(self.sg)
        ifwrs.client_set_for_tenant(self.server.tenant_id,
                                              fallback_to_api=True) \
                .AndReturn(tcs)
        tcs.compute.servers.add_security_group(self.server, self.sg.name)\
                .AndRaise(osc_exc.BadRequest('failure'))

        self.mox.ReplayAll()
        self.interact(expected_status_code=400)
    def test_create_no_description(self):
        params = {'project': u'TENANT', 'name': u'Test SG'}
        tcs = mock_client_set(self.mox)
        fw_rule_sets.client_set_for_tenant(u'TENANT', fallback_to_api=True,
                                           eperm_status=404) \
                .AndReturn(tcs)
        tcs.compute.security_groups.create(name=u'Test SG',
                                           description='').AndReturn('SG')
        fw_rule_sets._sg_to_view('SG').AndReturn('REPLY')

        self.mox.ReplayAll()

        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
Esempio n. 8
0
    def test_list_in_project(self):
        # differs with previous only in request argument
        tcs = mock_client_set(self.mox)
        fake_image_dict = {"name": "I1", "project": {"id": self.tenant.id}}

        self.fake_client_set.identity_admin.tenants.get(self.tenant.id).AndReturn(self.tenant)
        images.auth.client_set_for_tenant(self.tenant.id, fallback_to_api=False).AndReturn(tcs)
        tcs.image.images.list(filters={"is_public": False}).AndReturn(["ii1"])
        images._image_to_view("ii1", self.tenant).AndReturn(fake_image_dict)

        self.mox.ReplayAll()
        rv = self.client.get(u"/v1/images/?project:in=%s" % self.tenant.id)
        data = self.check_and_parse_response(rv)
        self.assertEquals(data.get("images"), [fake_image_dict])
    def test_add_works(self):
        compute = self.fake_client_set.compute
        tcs = mock_client_set(self.mox)

        compute.servers.get(self.server.id).AndReturn(self.server)
        compute.security_groups.get(self.sg_id).AndReturn(self.sg)
        ifwrs.client_set_for_tenant(self.server.tenant_id,
                                              fallback_to_api=True) \
                .AndReturn(tcs)
        tcs.compute.servers.add_security_group(self.server, self.sg.name)
        ifwrs.link_for_security_group(self.sg).AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact()
        self.assertEquals(data, 'REPLY')
    def test_list_for_my_projects(self):
        tenant = doubles.make(self.mox, doubles.Tenant, name='t1', id=u'PID1')

        self.fake_client_set.identity_public.tenants.list().AndReturn([tenant])

        tcs1 = mock_client_set(self.mox)
        fw_rule_sets.client_set_for_tenant(u'PID1', fallback_to_api=True) \
                .AndReturn(tcs1)
        tcs1.compute.security_groups.list().AndReturn(['SG1'])
        fw_rule_sets._sg_to_view('SG1', tenant.name).AndReturn('REPLY1')

        self.mox.ReplayAll()
        rv = self.client.get('/v1/fw-rule-sets/?my-projects=true')
        data = self.check_and_parse_response(rv)
        self.assertEquals(data.get('fw-rule-sets'), ['REPLY1'])
Esempio n. 11
0
    def test_list_for_project(self):
        tcs = mock_client_set(self.mox)
        tenant = self.tenants[1]

        self.fake_client_set.identity_admin.tenants.get(tenant.id).AndReturn(tenant)
        images.auth.client_set_for_tenant(tenant.id, fallback_to_api=True).AndReturn(tcs)
        tcs.image.images.list(filters={"is_public": None}).AndReturn(["ii1", "ii2"])
        images._image_to_view("ii1", self.tenants[0]).AndReturn("I1")
        images._image_to_view("ii2", self.tenants[1]).AndReturn("I2")

        expected = {u"collection": {u"name": u"images", u"size": 2}, u"images": ["I1", "I2"]}

        self.mox.ReplayAll()
        rv = self.client.get(u"/v1/images/?project:for=%s" % tenant.id)
        data = self.check_and_parse_response(rv)
        self.assertEquals(data, expected)
Esempio n. 12
0
    def test_list_for_project(self):
        tcs = mock_client_set(self.mox)

        self.fake_client_set.identity_admin.tenants.get(self.tenant.id)\
                .AndReturn(self.tenant)
        images.auth.client_set_for_tenant(self.tenant.id,
                                          fallback_to_api=False) \
                .AndReturn(tcs)
        tcs.image.images.list(filters={'is_public': None}) \
                .AndReturn(['ii1'])
        images._image_to_view('ii1', self.tenant).AndReturn('I1')

        self.mox.ReplayAll()
        rv = self.client.get(u'/v1/images/?project:for=%s' % self.tenant.id)
        data = self.check_and_parse_response(rv)
        self.assertEquals(data.get('images'), ['I1'])
    def test_list_for_my_projects(self):
        tenant = doubles.make(self.mox, doubles.Tenant,
                              name='t1', id=u'PID1')

        self.fake_client_set.identity_public.tenants.list().AndReturn([tenant])

        tcs1 = mock_client_set(self.mox)
        fw_rule_sets.client_set_for_tenant(u'PID1', fallback_to_api=True) \
                .AndReturn(tcs1)
        tcs1.compute.security_groups.list().AndReturn(['SG1'])
        fw_rule_sets._sg_to_view('SG1', tenant.name).AndReturn('REPLY1')

        self.mox.ReplayAll()
        rv = self.client.get('/v1/fw-rule-sets/?my-projects=true')
        data = self.check_and_parse_response(rv)
        self.assertEquals(data.get('fw-rule-sets'), ['REPLY1'])
    def test_create_no_description(self):
        params = {
            'project': u'TENANT',
            'name': u'Test SG'
        }
        tcs = mock_client_set(self.mox)
        fw_rule_sets.client_set_for_tenant(u'TENANT', fallback_to_api=True,
                                           eperm_status=404) \
                .AndReturn(tcs)
        tcs.compute.security_groups.create(
            name=u'Test SG', description='').AndReturn('SG')
        fw_rule_sets._sg_to_view('SG').AndReturn('REPLY')

        self.mox.ReplayAll()

        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
Esempio n. 15
0
    def test_create_local_image(self):
        params = {
            u"name": u"TestImage",
            u"project": u"PROJECT_ID",
            u"disk-format": u"raw",
            u"container-format": u"bare",
        }
        tcs = mock_client_set(self.mox)

        images.auth.client_set_for_tenant(u"PROJECT_ID").AndReturn(tcs)
        tcs.image.images.create(
            name=u"TestImage", disk_format=u"raw", container_format=u"bare", is_public=False, properties={}
        ).AndReturn("QueuedImage")
        images._image_to_view("QueuedImage").AndReturn("REPLY")

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, "REPLY")
Esempio n. 16
0
    def test_create_local_image(self):
        params = {
            u'name': u'TestImage',
            u'project': u'PROJECT_ID',
            u'disk-format': u'raw',
            u'container-format': u'bare',
        }
        tcs = mock_client_set(self.mox)

        images.auth.client_set_for_tenant(u'PROJECT_ID').AndReturn(tcs)
        tcs.image.images.create(
            name=u'TestImage',
            disk_format=u'raw',
            container_format=u'bare',
            is_public=False,
            properties={}).AndReturn('QueuedImage')
        images._image_to_view('QueuedImage').AndReturn('REPLY')

        self.mox.ReplayAll()
        data = self.interact(params)
        self.assertEquals(data, 'REPLY')
Esempio n. 17
0
    def test_list_in_project(self):
        # differs with previous only in request argument
        tcs = mock_client_set(self.mox)
        fake_image_dict = {
            'name': 'I1',
            'project': { 'id': self.tenant.id }
        }

        self.fake_client_set.identity_admin.tenants.get(self.tenant.id)\
                .AndReturn(self.tenant)
        images.auth.client_set_for_tenant(self.tenant.id,
                                          fallback_to_api=False) \
                .AndReturn(tcs)
        tcs.image.images.list(filters={'is_public': False}) \
                .AndReturn(['ii1'])
        images._image_to_view('ii1', self.tenant).AndReturn(fake_image_dict)

        self.mox.ReplayAll()
        rv = self.client.get(u'/v1/images/?project:in=%s' % self.tenant.id)
        data = self.check_and_parse_response(rv)
        self.assertEquals(data.get('images'), [fake_image_dict])
Esempio n. 18
0
 def setUp(self):
     super(CreateTestCase, self).setUp()
     self.mox.StubOutWithMock(instances, '_instance_to_view')
     self.mox.StubOutWithMock(instances, 'client_set_for_tenant')
     self.mox.StubOutWithMock(instances, 'InstanceDataDAO')
     self.tcs = mock_client_set(self.mox)
Esempio n. 19
0
 def setUp(self):
     super(CreateTestCase, self).setUp()
     self.mox.StubOutWithMock(instances, '_instance_to_view')
     self.mox.StubOutWithMock(instances, 'client_set_for_tenant')
     self.mox.StubOutWithMock(instances, 'InstanceDataDAO')
     self.tcs = mock_client_set(self.mox)