Exemplo n.º 1
0
 def test_install_bootloader_skips_if_unchanged(self):
     contents = factory.getRandomString()
     dest = self.make_file(contents=contents)
     age_file(dest, 100)
     original_write_time = get_write_time(dest)
     loader = self.make_file(contents=contents)
     install_bootloader(loader, dest)
     self.assertThat(dest, FileContains(contents))
     self.assertEqual(original_write_time, get_write_time(dest))
Exemplo n.º 2
0
 def test_skips_if_unchanged(self):
     contents = factory.make_bytes()
     dest = self.make_file(contents=contents)
     age_file(dest, 100)
     original_write_time = os.stat(dest).st_mtime
     loader = self.make_file(contents=contents)
     atomic_copy(loader, dest)
     self.assertThat(dest, FileContains(contents))
     self.assertEqual(original_write_time, os.stat(dest).st_mtime)
Exemplo n.º 3
0
 def test_install_bootloader_skips_if_unchanged(self):
     contents = factory.getRandomString()
     dest = self.make_file(contents=contents)
     age_file(dest, 100)
     original_write_time = get_write_time(dest)
     loader = self.make_file(contents=contents)
     install_bootloader(loader, dest)
     self.assertThat(dest, FileContains(contents))
     self.assertEqual(original_write_time, get_write_time(dest))
Exemplo n.º 4
0
    def test_meta_contains_updates_file_timestamp(self):
        content = factory.make_string()
        storage, meta_file = self.make_meta_file(content)

        # Change the file's timestamp to a week ago.
        one_week_ago = timedelta(weeks=1).total_seconds()
        age_file(meta_file, one_week_ago)

        boot_resources.meta_contains(storage, content)

        # Check the timestamp was updated.
        expected_date = datetime.now()
        actual_date = datetime.fromtimestamp(int(os.path.getmtime(meta_file)))
        self.assertEqual(expected_date.day, actual_date.day)
Exemplo n.º 5
0
    def fake_leases_file(self, leases=None, age=None):
        """Fake the presence of a leases file.

        This does not go through the leases parser.  It patches out the
        leases parser with a fake that returns the lease data you pass in
        here.

        :param leases: Dict of leases (mapping IP addresses to MACs).
        :param age: Number of seconds since last modification to leases file.
        :return: Path/name of temporary file.
        """
        if leases is None:
            leases = {}
        leases = leases.copy()
        leases_file = self.make_file()
        if age is not None:
            age_file(leases_file, age)
        timestamp = get_write_time(leases_file)
        self.redirect_parser(leases_file)
        self.patch(
            leases_module, 'parse_leases_file', lambda: (timestamp, leases))
        return leases_file
Exemplo n.º 6
0
    def fake_leases_file(self, leases=None, age=None):
        """Fake the presence of a leases file.

        This does not go through the leases parser.  It patches out the
        leases parser with a fake that returns the lease data you pass in
        here.

        :param leases: Dict of leases (mapping IP addresses to MACs).
        :param age: Number of seconds since last modification to leases file.
        :return: Path/name of temporary file.
        """
        if leases is None:
            leases = {}
        leases = leases.copy()
        leases_file = self.make_file()
        if age is not None:
            age_file(leases_file, age)
        timestamp = get_write_time(leases_file)
        self.redirect_parser(leases_file)
        self.patch(leases_module, 'parse_leases_file', lambda:
                   (timestamp, leases))
        return leases_file
Exemplo n.º 7
0
def backdate(path):
    """Set the last modification time for the file at `path` to the past."""
    age_file(path, 9999999)
Exemplo n.º 8
0
def backdate(path):
    """Set the last modification time for the file at `path` to the past."""
    age_file(path, 9999999)