summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-09-21 03:53:46 +0000
committerTarmac <>2010-09-21 03:53:46 +0000
commit8e3508e0109973056e7fd78809ef7ea94d949168 (patch)
tree0d9b560a36a5a174f944956cbd5e79c4c4c9403d
parentd8861d04a85044ae57ffd7eb9ab682879beecf7d (diff)
parent9330ebc110aeb7591567c66939b39f4345b5778d (diff)
downloadnova-8e3508e0109973056e7fd78809ef7ea94d949168.tar.gz
nova-8e3508e0109973056e7fd78809ef7ea94d949168.tar.xz
nova-8e3508e0109973056e7fd78809ef7ea94d949168.zip
Added modify project command to auth manager to allow changing of project manager and description.
-rw-r--r--nova/auth/fakeldap.py5
-rw-r--r--nova/auth/ldapdriver.py18
-rw-r--r--nova/auth/manager.py20
-rw-r--r--nova/tests/auth_unittest.py6
4 files changed, 48 insertions, 1 deletions
diff --git a/nova/auth/fakeldap.py b/nova/auth/fakeldap.py
index bfc3433c5..2791dfde6 100644
--- a/nova/auth/fakeldap.py
+++ b/nova/auth/fakeldap.py
@@ -33,6 +33,7 @@ SCOPE_ONELEVEL = 1 # not implemented
SCOPE_SUBTREE = 2
MOD_ADD = 0
MOD_DELETE = 1
+MOD_REPLACE = 2
class NO_SUCH_OBJECT(Exception): # pylint: disable-msg=C0103
@@ -175,7 +176,7 @@ class FakeLDAP(object):
Args:
dn -- a dn
attrs -- a list of tuples in the following form:
- ([MOD_ADD | MOD_DELETE], attribute, value)
+ ([MOD_ADD | MOD_DELETE | MOD_REPACE], attribute, value)
"""
redis = datastore.Redis.instance()
@@ -185,6 +186,8 @@ class FakeLDAP(object):
values = _from_json(redis.hget(key, k))
if cmd == MOD_ADD:
values.append(v)
+ elif cmd == MOD_REPLACE:
+ values = [v]
else:
values.remove(v)
values = redis.hset(key, k, _to_json(values))
diff --git a/nova/auth/ldapdriver.py b/nova/auth/ldapdriver.py
index 74ba011b5..cc8e2caa3 100644
--- a/nova/auth/ldapdriver.py
+++ b/nova/auth/ldapdriver.py
@@ -202,6 +202,24 @@ class LdapDriver(object):
self.conn.add_s('cn=%s,%s' % (name, FLAGS.ldap_project_subtree), attr)
return self.__to_project(dict(attr))
+ def modify_project(self, project_id, manager_uid=None, description=None):
+ """Modify an existing project"""
+ if not manager_uid and not description:
+ return
+ attr = []
+ if manager_uid:
+ if not self.__user_exists(manager_uid):
+ raise exception.NotFound("Project can't be modified because "
+ "manager %s doesn't exist" %
+ manager_uid)
+ manager_dn = self.__uid_to_dn(manager_uid)
+ attr.append((self.ldap.MOD_REPLACE, 'projectManager', manager_dn))
+ if description:
+ attr.append((self.ldap.MOD_REPLACE, 'description', description))
+ self.conn.modify_s('cn=%s,%s' % (project_id,
+ FLAGS.ldap_project_subtree),
+ attr)
+
def add_to_project(self, uid, project_id):
"""Add user to project"""
dn = 'cn=%s,%s' % (project_id, FLAGS.ldap_project_subtree)
diff --git a/nova/auth/manager.py b/nova/auth/manager.py
index d5fbec7c5..c4efc03de 100644
--- a/nova/auth/manager.py
+++ b/nova/auth/manager.py
@@ -533,6 +533,26 @@ class AuthManager(object):
raise
return project
+ def modify_project(self, project, manager_user=None, description=None):
+ """Modify a project
+
+ @type name: Project or project_id
+ @param project: The project to modify.
+
+ @type manager_user: User or uid
+ @param manager_user: This user will be the new project manager.
+
+ @type description: str
+ @param project: This will be the new description of the project.
+
+ """
+ if manager_user:
+ manager_user = User.safe_id(manager_user)
+ with self.driver() as drv:
+ drv.modify_project(Project.safe_id(project),
+ manager_user,
+ description)
+
def add_to_project(self, user, project):
"""Add user to project"""
with self.driver() as drv:
diff --git a/nova/tests/auth_unittest.py b/nova/tests/auth_unittest.py
index b54e68274..c19f5a9b4 100644
--- a/nova/tests/auth_unittest.py
+++ b/nova/tests/auth_unittest.py
@@ -204,6 +204,12 @@ class AuthTestCase(test.BaseTestCase):
self.assert_(len(self.manager.get_projects()) > 1)
self.assertEqual(len(self.manager.get_projects('test2')), 1)
+ def test_220_can_modify_project(self):
+ self.manager.modify_project('testproj', 'test2', 'new description')
+ project = self.manager.get_project('testproj')
+ self.assertEqual(project.project_manager_id, 'test2')
+ self.assertEqual(project.description, 'new description')
+
def test_299_can_delete_project(self):
self.manager.delete_project('testproj')
self.assertFalse(filter(lambda p: p.name == 'testproj', self.manager.get_projects()))