← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~jtv/maas/epoch-tarball into lp:maas

 

Jeroen T. Vermeulen has proposed merging lp:~jtv/maas/epoch-tarball into lp:maas.

Commit message:
Set sane timestamps on the commissioning scripts inside the archive the nodes download from the metadata service.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jtv/maas/epoch-tarball/+merge/140879

This should silence a warning that commissioning nodes issue otherwise: the metadata service generates a tarball of commissioning scripts.  A commissioning node downloads and unpacks that tarball.  But the scripts inside the tarball have their timestamps set to the epoch, and the nodes complain about it.

And so this branch just sets the current time.  Doesn't have to be very exact, really.  Nodes may still complain if their clock was behind, for instance, when they see timestamps from the future.  But at least there won't be a warning that's actually inappropriate.  "My clock is dramatically slow" may actually be useful debugging information, so I didn't go out of my way to suppress that one.


Jeroen
-- 
https://code.launchpad.net/~jtv/maas/epoch-tarball/+merge/140879
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~jtv/maas/epoch-tarball into lp:maas.
=== modified file 'src/metadataserver/models/commissioningscript.py'
--- src/metadataserver/models/commissioningscript.py	2012-12-17 15:30:48 +0000
+++ src/metadataserver/models/commissioningscript.py	2012-12-20 11:46:48 +0000
@@ -19,6 +19,7 @@
 import os.path
 import tarfile
 from textwrap import dedent
+import time
 
 from django.db.models import (
     CharField,
@@ -47,12 +48,13 @@
 }
 
 
-def add_script_to_archive(tarball, name, content):
+def add_script_to_archive(tarball, name, content, mtime):
     """Add a commissioning script to an archive of commissioning scripts."""
     assert isinstance(content, bytes), "Script content must be binary."
     tarinfo = tarfile.TarInfo(name=os.path.join(ARCHIVE_PREFIX, name))
     tarinfo.size = len(content)
     tarinfo.mode = 0755  # u=rwx,go=rx
+    tarinfo.mtime = mtime
     tarball.addfile(tarinfo, BytesIO(content))
 
 
@@ -64,13 +66,15 @@
 
         Each of the scripts will be in the `ARCHIVE_PREFIX` directory.
         """
+        mtime = time.time()
         binary = BytesIO()
         tarball = tarfile.open(mode='w', fileobj=binary)
         scripts = sorted(
             BUILTIN_COMMISSIONING_SCRIPTS.items() +
             [(script.name, script.content) for script in self.all()])
         for name, content in scripts:
-            add_script_to_archive(tarball, name, content)
+            add_script_to_archive(
+                tarball=tarball, name=name, content=content, mtime=mtime)
         tarball.close()
         binary.seek(0)
         return binary.read()

=== modified file 'src/metadataserver/tests/test_commissioningscript.py'
--- src/metadataserver/tests/test_commissioningscript.py	2012-12-18 12:21:57 +0000
+++ src/metadataserver/tests/test_commissioningscript.py	2012-12-20 11:46:48 +0000
@@ -13,9 +13,14 @@
 __all__ = []
 
 from io import BytesIO
+from math import (
+    ceil,
+    floor,
+    )
 import os.path
 from random import randint
 import tarfile
+import time
 
 from maasserver.testing.factory import factory
 from maasserver.testing.testcase import TestCase
@@ -84,6 +89,16 @@
         archive = open_tarfile(CommissioningScript.objects.get_archive())
         self.assertEqual({0755}, {info.mode for info in archive.getmembers()})
 
+    def test_get_archive_initializes_file_timestamps(self):
+        start_time = floor(time.time())
+        script = factory.make_commissioning_script()
+        path = os.path.join(ARCHIVE_PREFIX, script.name)
+        archive = open_tarfile(CommissioningScript.objects.get_archive())
+        timestamp = archive.getmember(path).mtime
+        end_time = ceil(time.time())
+        self.assertGreaterEqual(timestamp, start_time)
+        self.assertLessEqual(timestamp, end_time)
+
 
 class TestCommissioningScript(TestCase):