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_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.º 3
0
 def test_leaves_install_image_untouched_if_unchanged(self):
     arch = self.get_arch()
     release = 'precise'
     archive = self.make_downloads(arch=arch, release=release)
     self.call_script(archive, self.tftproot, arch=arch, release=release)
     tftp_path = compose_tftp_path(self.tftproot, arch, release, 'install',
                                   'linux')
     backdate(tftp_path)
     original_timestamp = get_write_time(tftp_path)
     self.call_script(archive, self.tftproot, arch=arch, release=release)
     self.assertEqual(original_timestamp, get_write_time(tftp_path))
Exemplo n.º 4
0
 def test_leaves_install_image_untouched_if_unchanged(self):
     arch = self.get_arch()
     release = 'precise'
     archive = self.make_downloads(arch=arch, release=release)
     self.call_script(archive, self.tftproot, arch=arch, release=release)
     tftp_path = compose_tftp_path(
         self.tftproot, arch, release, 'install', 'linux')
     backdate(tftp_path)
     original_timestamp = get_write_time(tftp_path)
     self.call_script(archive, self.tftproot, arch=arch, release=release)
     self.assertEqual(original_timestamp, get_write_time(tftp_path))
Exemplo n.º 5
0
 def test_check_lease_changes_returns_tuple_if_no_state_cached(self):
     self.set_lease_state()
     leases = factory.make_random_leases()
     leases_file = self.fake_leases_file(leases)
     self.assertEqual(
         (get_write_time(leases_file), leases),
         check_lease_changes())
Exemplo n.º 6
0
 def test_check_lease_changes_does_not_parse_unchanged_leases_file(self):
     parser = FakeMethod()
     leases_file = self.fake_leases_file()
     self.patch(leases_module, 'parse_leases_file', parser)
     self.set_lease_state(get_write_time(leases_file), {})
     update_leases()
     self.assertSequenceEqual([], parser.calls)
Exemplo n.º 7
0
 def test_check_lease_changes_does_not_parse_unchanged_leases_file(self):
     parser = FakeMethod()
     leases_file = self.fake_leases_file()
     self.patch(leases_module, 'parse_leases_file', parser)
     self.set_lease_state(get_write_time(leases_file), {})
     update_leases()
     self.assertSequenceEqual([], parser.calls)
Exemplo n.º 8
0
 def test_update_leases_does_nothing_without_lease_changes(self):
     fake_send_leases = FakeMethod()
     self.patch(leases_module, 'send_leases', fake_send_leases)
     leases = factory.make_random_leases()
     leases_file = self.fake_leases_file(leases)
     self.set_lease_state(get_write_time(leases_file), leases.copy())
     self.assertEqual([], leases_module.send_leases.calls)
Exemplo n.º 9
0
 def test_update_leases_does_nothing_without_lease_changes(self):
     fake_send_leases = FakeMethod()
     self.patch(leases_module, 'send_leases', fake_send_leases)
     leases = factory.make_random_leases()
     leases_file = self.fake_leases_file(leases)
     self.set_lease_state(get_write_time(leases_file), leases.copy())
     self.assertEqual([], leases_module.send_leases.calls)
Exemplo n.º 10
0
 def test_check_lease_changes_returns_tuple_if_leases_dropped(self):
     self.set_lease_state(
         datetime.utcnow() - timedelta(seconds=10),
         factory.make_random_leases())
     leases_file = self.fake_leases_file({})
     self.assertEqual(
         (get_write_time(leases_file), {}),
         check_lease_changes())
Exemplo n.º 11
0
 def test_check_lease_changes_returns_tuple_if_lease_added(self):
     leases = factory.make_random_leases()
     self.set_lease_state(datetime.utcnow() - timedelta(seconds=10),
                          leases.copy())
     leases[factory.getRandomIPAddress()] = factory.getRandomMACAddress()
     leases_file = self.fake_leases_file(leases)
     self.assertEqual((get_write_time(leases_file), leases),
                      check_lease_changes())
Exemplo n.º 12
0
 def test_upload_leases_processes_leases_unconditionally(self):
     leases = factory.make_random_leases()
     leases_file = self.fake_leases_file(leases)
     self.set_lease_state(get_write_time(leases_file), leases.copy())
     self.patch(leases_module, 'send_leases', FakeMethod())
     upload_leases()
     self.assertEqual([(leases, )],
                      leases_module.send_leases.extract_args())
Exemplo n.º 13
0
 def test_upload_leases_processes_leases_unconditionally(self):
     leases = factory.make_random_leases()
     leases_file = self.fake_leases_file(leases)
     self.set_lease_state(get_write_time(leases_file), leases.copy())
     self.patch(leases_module, 'send_leases', FakeMethod())
     upload_leases()
     self.assertEqual(
         [(leases, )],
         leases_module.send_leases.extract_args())
Exemplo n.º 14
0
 def test_check_lease_changes_returns_tuple_if_lease_added(self):
     leases = factory.make_random_leases()
     self.set_lease_state(
         datetime.utcnow() - timedelta(seconds=10), leases.copy())
     leases[factory.getRandomIPAddress()] = factory.getRandomMACAddress()
     leases_file = self.fake_leases_file(leases)
     self.assertEqual(
         (get_write_time(leases_file), leases),
         check_lease_changes())
Exemplo n.º 15
0
 def test_parse_leases_file_parses_leases(self):
     params = {
         'ip': factory.getRandomIPAddress(),
         'mac': factory.getRandomMACAddress(),
     }
     leases_file = self.write_leases_file("""\
         lease %(ip)s {
             starts 5 2010/01/01 00:00:01;
             ends never;
             tstp 6 2010/01/02 05:00:00;
             tsfp 6 2010/01/02 05:00:00;
             binding state free;
             hardware ethernet %(mac)s;
         }
         """ % params)
     self.assertEqual(
         (get_write_time(leases_file), {params['ip']: params['mac']}),
         parse_leases_file())
Exemplo n.º 16
0
 def test_parse_leases_file_parses_leases(self):
     params = {
         'ip': factory.getRandomIPAddress(),
         'mac': factory.getRandomMACAddress(),
     }
     leases_file = self.write_leases_file("""\
         lease %(ip)s {
             starts 5 2010/01/01 00:00:01;
             ends never;
             tstp 6 2010/01/02 05:00:00;
             tsfp 6 2010/01/02 05:00:00;
             binding state free;
             hardware ethernet %(mac)s;
         }
         """ % params)
     self.assertEqual((get_write_time(leases_file), {
         params['ip']: params['mac']
     }), parse_leases_file())
Exemplo n.º 17
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.º 18
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.º 19
0
 def test_check_lease_changes_returns_None_if_no_change(self):
     leases = factory.make_random_leases()
     leases_file = self.fake_leases_file(leases)
     self.set_lease_state(get_write_time(leases_file), leases.copy())
     self.assertIsNone(check_lease_changes())
Exemplo n.º 20
0
 def test_check_lease_changes_returns_None_if_no_change(self):
     leases = factory.make_random_leases()
     leases_file = self.fake_leases_file(leases)
     self.set_lease_state(get_write_time(leases_file), leases.copy())
     self.assertIsNone(check_lease_changes())
Exemplo n.º 21
0
 def test_check_lease_changes_returns_tuple_if_no_state_cached(self):
     self.set_lease_state()
     leases = factory.make_random_leases()
     leases_file = self.fake_leases_file(leases)
     self.assertEqual((get_write_time(leases_file), leases),
                      check_lease_changes())
Exemplo n.º 22
0
 def test_check_lease_changes_returns_tuple_if_leases_dropped(self):
     self.set_lease_state(datetime.utcnow() - timedelta(seconds=10),
                          factory.make_random_leases())
     leases_file = self.fake_leases_file({})
     self.assertEqual((get_write_time(leases_file), {}),
                      check_lease_changes())