Example #1
0
 def test_list_role_assignments_keystone_v2_with_role(
         self, mock_keystone, mock_api_version):
     fake_role1 = fakes.FakeRole(id='1234', name='fake_role')
     fake_role2 = fakes.FakeRole(id='4321', name='fake_role')
     mock_api_version.return_value = '2.0'
     mock_keystone.roles.roles_for_user.return_value = [
         fake_role1, fake_role2
     ]
     ret = self.op_cloud.list_role_assignments(filters={
         'role': fake_role1.id,
         'user': '******',
         'project': '3333'
     })
     self.assertEqual(ret, [{
         'id': fake_role1.id,
         'project': '3333',
         'user': '******'
     }])
Example #2
0
    def test_create_role(self, mock_keystone):
        role_name = 'tootsie_roll'
        role_obj = fakes.FakeRole(id='1234', name=role_name)
        mock_keystone.roles.create.return_value = role_obj

        role = self.op_cloud.create_role(role_name)

        mock_keystone.roles.create.assert_called_once_with(name=role_name)
        self.assertIsNotNone(role)
        self.assertEqual(role_name, role['name'])
Example #3
0
    def test_get_role(self, mock_keystone):
        role_obj = fakes.FakeRole(id='1234', name='fake_role')
        mock_keystone.roles.list.return_value = [role_obj]

        role = self.op_cloud.get_role('fake_role')

        self.assertTrue(mock_keystone.roles.list.called)
        self.assertIsNotNone(role)
        self.assertEqual('1234', role['id'])
        self.assertEqual('fake_role', role['name'])
Example #4
0
 def test_delete_role(self, mock_keystone, mock_get):
     role_obj = fakes.FakeRole(id='1234', name='aaa')
     mock_get.return_value = meta.obj_to_dict(role_obj)
     self.assertTrue(self.op_cloud.delete_role('1234'))
     self.assertTrue(mock_keystone.roles.delete.called)
Example #5
0
 def setUp(self):
     super(TestRoleAssignment, self).setUp()
     self.fake_role = obj_to_dict(fakes.FakeRole('12345', 'test'))
     self.fake_user = obj_to_dict(
         fakes.FakeUser('12345',
                        '*****@*****.**',
                        'test',
                        domain_id='test-domain'))
     self.fake_group = obj_to_dict(
         fakes.FakeGroup('12345',
                         'test',
                         'test group',
                         domain_id='test-domain'))
     self.fake_project = obj_to_dict(
         fakes.FakeProject('12345', domain_id='test-domain'))
     self.fake_domain = obj_to_dict(
         fakes.FakeDomain('test-domain',
                          'test',
                          'test domain',
                          enabled=True))
     self.user_project_assignment = obj_to_dict({
         'role': {
             'id': self.fake_role['id']
         },
         'scope': {
             'project': {
                 'id': self.fake_project['id']
             }
         },
         'user': {
             'id': self.fake_user['id']
         }
     })
     self.group_project_assignment = obj_to_dict({
         'role': {
             'id': self.fake_role['id']
         },
         'scope': {
             'project': {
                 'id': self.fake_project['id']
             }
         },
         'group': {
             'id': self.fake_group['id']
         }
     })
     self.user_domain_assignment = obj_to_dict({
         'role': {
             'id': self.fake_role['id']
         },
         'scope': {
             'domain': {
                 'id': self.fake_domain['id']
             }
         },
         'user': {
             'id': self.fake_user['id']
         }
     })
     self.group_domain_assignment = obj_to_dict({
         'role': {
             'id': self.fake_role['id']
         },
         'scope': {
             'domain': {
                 'id': self.fake_domain['id']
             }
         },
         'group': {
             'id': self.fake_group['id']
         }
     })