← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~allenap/maas/pserv-xmlrpc-stuff-by-name into lp:maas

 

Gavin Panella has proposed merging lp:~allenap/maas/pserv-xmlrpc-stuff-by-name into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~allenap/maas/pserv-xmlrpc-stuff-by-name/+merge/91870

Add methods to the Provisioning API to get things (distros/profiles/nodes) by name, and delete them by name.
-- 
https://code.launchpad.net/~allenap/maas/pserv-xmlrpc-stuff-by-name/+merge/91870
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/pserv-xmlrpc-stuff-by-name into lp:maas.
=== modified file 'src/provisioningserver/remote.py'
--- src/provisioningserver/remote.py	2012-02-06 20:50:24 +0000
+++ src/provisioningserver/remote.py	2012-02-07 16:26:20 +0000
@@ -44,13 +44,6 @@
         returnValue(distro.name)
 
     @inlineCallbacks
-    def xmlrpc_get_distros(self):
-        # WARNING: This could return a *huge* number of results. Consider
-        # adding filtering options to this function before using it in anger.
-        distros = yield CobblerDistro.get_all_values(self.session)
-        returnValue(distros)
-
-    @inlineCallbacks
     def xmlrpc_add_profile(self, name, distro):
         assert isinstance(name, basestring)
         assert isinstance(distro, basestring)
@@ -59,13 +52,6 @@
         returnValue(profile.name)
 
     @inlineCallbacks
-    def xmlrpc_get_profiles(self):
-        # WARNING: This could return a *huge* number of results. Consider
-        # adding filtering options to this function before using it in anger.
-        profiles = yield CobblerProfile.get_all_values(self.session)
-        returnValue(profiles)
-
-    @inlineCallbacks
     def xmlrpc_add_node(self, name, profile):
         assert isinstance(name, basestring)
         assert isinstance(profile, basestring)
@@ -74,6 +60,69 @@
         returnValue(system.name)
 
     @inlineCallbacks
+    def get_objects_by_name(self, object_type, names):
+        """Get `object_type` objects by name.
+
+        :param object_type: The type of object to look for.
+        :type object_type: provisioningserver.objectclient.CobblerObjectType
+        :param names: A list of names to search for.
+        :type names: list
+        """
+        objects_by_name = {}
+        for name in names:
+            objects = yield object_type.find(self.session, name=name)
+            for obj in objects:
+                values = yield obj.get_values()
+                objects_by_name[obj.name] = values
+        returnValue(objects_by_name)
+
+    def xmlrpc_get_distros_by_name(self, names):
+        return self.get_objects_by_name(CobblerDistro, names)
+
+    def xmlrpc_get_profiles_by_name(self, names):
+        return self.get_objects_by_name(CobblerProfile, names)
+
+    def xmlrpc_get_nodes_by_name(self, names):
+        return self.get_objects_by_name(CobblerSystem, names)
+
+    @inlineCallbacks
+    def delete_objects_by_name(self, object_type, names):
+        """Delete `object_type` objects by name.
+
+        :param object_type: The type of object to delete.
+        :type object_type: provisioningserver.objectclient.CobblerObjectType
+        :param names: A list of names to search for.
+        :type names: list
+        """
+        for name in names:
+            objects = yield object_type.find(self.session, name=name)
+            for obj in objects:
+                yield obj.delete()
+
+    def xmlrpc_delete_distros_by_name(self, names):
+        return self.delete_objects_by_name(CobblerDistro, names)
+
+    def xmlrpc_delete_profiles_by_name(self, names):
+        return self.delete_objects_by_name(CobblerProfile, names)
+
+    def xmlrpc_delete_nodes_by_name(self, names):
+        return self.delete_objects_by_name(CobblerSystem, names)
+
+    @inlineCallbacks
+    def xmlrpc_get_distros(self):
+        # WARNING: This could return a *huge* number of results. Consider
+        # adding filtering options to this function before using it in anger.
+        distros = yield CobblerDistro.get_all_values(self.session)
+        returnValue(distros)
+
+    @inlineCallbacks
+    def xmlrpc_get_profiles(self):
+        # WARNING: This could return a *huge* number of results. Consider
+        # adding filtering options to this function before using it in anger.
+        profiles = yield CobblerProfile.get_all_values(self.session)
+        returnValue(profiles)
+
+    @inlineCallbacks
     def xmlrpc_get_nodes(self):
         # WARNING: This could return a *huge* number of results. Consider
         # adding filtering options to this function before using it in anger.

=== modified file 'src/provisioningserver/tests/test_remote.py'
--- src/provisioningserver/tests/test_remote.py	2012-02-06 20:26:51 +0000
+++ src/provisioningserver/tests/test_remote.py	2012-02-07 16:26:20 +0000
@@ -35,19 +35,79 @@
         cobbler_session.proxy = cobbler_proxy
         return cobbler_session
 
+    def get_provisioning_api(self):
+        cobbler_session = self.get_cobbler_session()
+        return ProvisioningAPI(cobbler_session)
+
     @inlineCallbacks
     def test_add_distro(self):
-        cobbler_session = self.get_cobbler_session()
         # Create a distro via the Provisioning API.
-        prov = ProvisioningAPI(cobbler_session)
+        prov = self.get_provisioning_api()
         distro = yield prov.xmlrpc_add_distro(
             "distro", "an_initrd", "a_kernel")
         self.assertEqual("distro", distro)
 
     @inlineCallbacks
+    def test_add_profile(self):
+        # Create a profile via the Provisioning API.
+        prov = self.get_provisioning_api()
+        distro = yield prov.xmlrpc_add_distro(
+            "distro", "an_initrd", "a_kernel")
+        profile = yield prov.xmlrpc_add_profile("profile", distro)
+        self.assertEqual("profile", profile)
+
+    @inlineCallbacks
+    def test_add_node(self):
+        # Create a system/node via the Provisioning API.
+        prov = self.get_provisioning_api()
+        distro = yield prov.xmlrpc_add_distro(
+            "distro", "an_initrd", "a_kernel")
+        profile = yield prov.xmlrpc_add_profile("profile", distro)
+        node = yield prov.xmlrpc_add_node("node", profile)
+        self.assertEqual("node", node)
+
+    @inlineCallbacks
+    def test_delete_distros_by_name(self):
+        # Create a distro via the Provisioning API.
+        prov = self.get_provisioning_api()
+        distro = yield prov.xmlrpc_add_distro(
+            "distro", "an_initrd", "a_kernel")
+        # Delete it again via the Provisioning API.
+        yield prov.xmlrpc_delete_distros_by_name([distro])
+        # It has gone, checked via the Cobbler session.
+        distros = yield prov.xmlrpc_get_distros_by_name([distro])
+        self.assertEqual({}, distros)
+
+    @inlineCallbacks
+    def test_delete_profiles_by_name(self):
+        # Create a profile via the Provisioning API.
+        prov = self.get_provisioning_api()
+        distro = yield prov.xmlrpc_add_distro(
+            "distro", "an_initrd", "a_kernel")
+        profile = yield prov.xmlrpc_add_profile("profile", distro)
+        # Delete it again via the Provisioning API.
+        yield prov.xmlrpc_delete_profiles_by_name([profile])
+        # It has gone, checked via the Cobbler session.
+        profiles = yield prov.xmlrpc_get_profiles_by_name([profile])
+        self.assertEqual({}, profiles)
+
+    @inlineCallbacks
+    def test_delete_nodes_by_name(self):
+        # Create a node via the Provisioning API.
+        prov = self.get_provisioning_api()
+        distro = yield prov.xmlrpc_add_distro(
+            "distro", "an_initrd", "a_kernel")
+        profile = yield prov.xmlrpc_add_profile("profile", distro)
+        node = yield prov.xmlrpc_add_node("node", profile)
+        # Delete it again via the Provisioning API.
+        yield prov.xmlrpc_delete_nodes_by_name([node])
+        # It has gone, checked via the Cobbler session.
+        nodes = yield prov.xmlrpc_get_nodes_by_name([node])
+        self.assertEqual({}, nodes)
+
+    @inlineCallbacks
     def test_get_distros(self):
-        cobbler_session = self.get_cobbler_session()
-        prov = ProvisioningAPI(cobbler_session)
+        prov = self.get_provisioning_api()
         distros = yield prov.xmlrpc_get_distros()
         self.assertEqual({}, distros)
         # Create some distros via the Provisioning API.
@@ -66,19 +126,8 @@
         self.assertEqual(expected, distros)
 
     @inlineCallbacks
-    def test_add_profile(self):
-        cobbler_session = self.get_cobbler_session()
-        # Create a profile via the Provisioning API.
-        prov = ProvisioningAPI(cobbler_session)
-        distro = yield prov.xmlrpc_add_distro(
-            "distro", "an_initrd", "a_kernel")
-        profile = yield prov.xmlrpc_add_profile("profile", distro)
-        self.assertEqual("profile", profile)
-
-    @inlineCallbacks
     def test_get_profiles(self):
-        cobbler_session = self.get_cobbler_session()
-        prov = ProvisioningAPI(cobbler_session)
+        prov = self.get_provisioning_api()
         distro = yield prov.xmlrpc_add_distro(
             "distro", "an_initrd", "a_kernel")
         profiles = yield prov.xmlrpc_get_profiles()
@@ -93,20 +142,8 @@
         self.assertEqual(expected, profiles)
 
     @inlineCallbacks
-    def test_add_node(self):
-        cobbler_session = self.get_cobbler_session()
-        # Create a system/node via the Provisioning API.
-        prov = ProvisioningAPI(cobbler_session)
-        distro = yield prov.xmlrpc_add_distro(
-            "distro", "an_initrd", "a_kernel")
-        profile = yield prov.xmlrpc_add_profile("profile", distro)
-        node = yield prov.xmlrpc_add_node("node", profile)
-        self.assertEqual("node", node)
-
-    @inlineCallbacks
     def test_get_nodes(self):
-        cobbler_session = self.get_cobbler_session()
-        prov = ProvisioningAPI(cobbler_session)
+        prov = self.get_provisioning_api()
         distro = yield prov.xmlrpc_add_distro(
             "distro", "an_initrd", "a_kernel")
         profile = yield prov.xmlrpc_add_profile("profile", distro)
@@ -120,3 +157,39 @@
             expected[name] = {'name': name, 'profile': 'profile'}
         nodes = yield prov.xmlrpc_get_nodes()
         self.assertEqual(expected, nodes)
+
+    @inlineCallbacks
+    def test_get_nodes_by_name(self):
+        prov = self.get_provisioning_api()
+        nodes = yield prov.xmlrpc_get_nodes_by_name([])
+        self.assertEqual({}, nodes)
+        # Create a node via the Provisioning API.
+        distro = yield prov.xmlrpc_add_distro("distro", "initrd", "kernel")
+        profile = yield prov.xmlrpc_add_profile("profile", distro)
+        yield prov.xmlrpc_add_node("alice", profile)
+        nodes = yield prov.xmlrpc_get_nodes_by_name(["alice", "bob"])
+        # The response contains keys for all systems found.
+        self.assertSequenceEqual(["alice"], sorted(nodes))
+
+    @inlineCallbacks
+    def test_get_distros_by_name(self):
+        prov = self.get_provisioning_api()
+        distros = yield prov.xmlrpc_get_distros_by_name([])
+        self.assertEqual({}, distros)
+        # Create a distro via the Provisioning API.
+        yield prov.xmlrpc_add_distro("alice", "initrd", "kernel")
+        distros = yield prov.xmlrpc_get_distros_by_name(["alice", "bob"])
+        # The response contains keys for all distributions found.
+        self.assertSequenceEqual(["alice"], sorted(distros))
+
+    @inlineCallbacks
+    def test_get_profiles_by_name(self):
+        prov = self.get_provisioning_api()
+        profiles = yield prov.xmlrpc_get_profiles_by_name([])
+        self.assertEqual({}, profiles)
+        # Create a profile via the Provisioning API.
+        distro = yield prov.xmlrpc_add_distro("distro", "initrd", "kernel")
+        yield prov.xmlrpc_add_profile("alice", distro)
+        profiles = yield prov.xmlrpc_get_profiles_by_name(["alice", "bob"])
+        # The response contains keys for all profiles found.
+        self.assertSequenceEqual(["alice"], sorted(profiles))