← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/factory-commissioning-script into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/factory-commissioning-script into lp:maas.

Commit message:
Factory method for CommissioningScript.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jtv/maas/factory-commissioning-script/+merge/135872

I'm extracting this from the larger branch I'm working on, exactly because it's so large.  My tests there make intense use of the new method.

There are no tests for the factory method.  I think it's simple and idiomatic enough that there's just not much to test.  Apart from the handling of binary data maybe, but that's all covered by tests for metadataserver.fields.


Jeroen
-- 
https://code.launchpad.net/~jtv/maas/factory-commissioning-script/+merge/135872
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/factory-commissioning-script into lp:maas.
=== modified file 'src/maasserver/testing/factory.py'
--- src/maasserver/testing/factory.py	2012-11-08 10:05:27 +0000
+++ src/maasserver/testing/factory.py	2012-11-23 11:23:36 +0000
@@ -43,7 +43,11 @@
     )
 from maasserver.utils import map_enum
 import maastesting.factory
-from metadataserver.models import NodeCommissionResult
+from metadataserver.fields import Bin
+from metadataserver.models import (
+    CommissioningScript,
+    NodeCommissionResult,
+    )
 from netaddr import IPAddress
 
 # We have a limited number of public keys:
@@ -344,6 +348,14 @@
             release=release,
             purpose=purpose)
 
+    def make_commissioning_script(self, name=None, content=None):
+        if name is None:
+            name = self.make_name('script')
+        if content is None:
+            content = b'content:' + self.getRandomString().encode('ascii')
+        return CommissioningScript.objects.create(
+            name=name, content=Bin(content))
+
 
 # Create factory singleton.
 factory = Factory()