Exemplo n.º 1
0
 def test_set_none_works_with_missing_file(self):
     contents = factory.make_name("contents")
     env.set_maas_id(contents)
     atomic_delete(self.maas_id_path)
     env.set_maas_id(None)
     self.assertIsNone(env.get_maas_id())
     self.assertFalse(os.path.exists(self.maas_id_path))
Exemplo n.º 2
0
 def test_set_None_clears_cache_if_maas_id_file_does_not_exist(self):
     contents = factory.make_name("contents")
     env.set_maas_id(contents)
     self.assertThat(env.get_maas_id(), Equals(contents))
     os.unlink(self.maas_id_path)
     env.set_maas_id(None)
     self.assertThat(env.get_maas_id(), Is(None))
Exemplo n.º 3
0
 def test_set_none_clears_cache(self):
     contents = factory.make_name("contents")
     env.set_maas_id(contents)
     self.assertEquals(contents, env.get_maas_id())
     env.set_maas_id(None)
     self.assertIsNone(env.get_maas_id())
     self.assertFalse(os.path.exists(self.maas_id_path))
Exemplo n.º 4
0
 def test_set_does_not_cache_when_write_fails(self):
     mock_atomic_write = self.patch_autospec(env, "atomic_write")
     exception = factory.make_exception()
     mock_atomic_write.side_effect = exception
     contents = factory.make_name("contents")
     with ExpectedException(type(exception)):
         env.set_maas_id(contents)
     self.assertIsNone(env.get_maas_id())
Exemplo n.º 5
0
def run(args):
    """Register the rack controller with a region controller."""
    # If stdin supplied to program URL must be passed as argument.
    if not stdin.isatty() and args.url is None:
        print(
            "MAAS region controller URL must be given when supplying the "
            "shared secret via stdin with a non-interactive shell."
        )
        raise SystemExit(1)
    try:
        call_and_check(["systemctl", "stop", "maas-rackd"])
    except ExternalProcessError as e:
        print("Unable to stop maas-rackd service.", file=stderr)
        print("Failed with error: %s." % e.output_as_unicode, file=stderr)
        raise SystemExit(1)
    # maas_id could be stale so remove it
    set_maas_id(None)
    if args.url is not None:
        with ClusterConfiguration.open_for_update() as config:
            config.maas_url = args.url
    else:
        try:
            url = input("MAAS region controller URL: ")
        except EOFError:
            print()  # So that the shell prompt appears on the next line.
            raise SystemExit(1)
        except KeyboardInterrupt:
            print()  # So that the shell prompt appears on the next line.
            raise
        with ClusterConfiguration.open_for_update() as config:
            config.maas_url = url
        print("MAAS region controller URL saved as %s." % url)
    if args.secret is not None:
        set_shared_secret_on_filesystem(to_bin(args.secret))
    else:
        InstallSharedSecretScript.run(args)
    try:
        call_and_check(["systemctl", "enable", "maas-rackd"])
        call_and_check(["systemctl", "start", "maas-rackd"])
    except ExternalProcessError as e:
        print(
            "Unable to enable and start the maas-rackd service.", file=stderr
        )
        print("Failed with error: %s." % e.output_as_unicode, file=stderr)
        raise SystemExit(1)
Exemplo n.º 6
0
 def setUp(self):
     super(TestMAASID, self).setUp()
     self.maas_id_path = get_data_path("/var/lib/maas/maas_id")
     self.addCleanup(env.set_maas_id, None)
     env.set_maas_id(None)
Exemplo n.º 7
0
 def test_set_caches_to_normalized_value(self):
     contents = "  %s  " % factory.make_name("contents")
     env.set_maas_id(contents)
     self.assertEquals(env._normalise_maas_id(contents), env.get_maas_id())
Exemplo n.º 8
0
 def test_set_None_clears_cache(self):
     contents = factory.make_name("contents")
     env.set_maas_id(contents)
     self.assertThat(env.get_maas_id(), Equals(contents))
     env.set_maas_id(None)
     self.assertThat(env.get_maas_id(), Is(None))
Exemplo n.º 9
0
 def test_set_caches(self):
     contents = factory.make_name("contents")
     env.set_maas_id(contents)
     os.unlink(self.maas_id_path)
     self.assertEquals(contents, env.get_maas_id())
Exemplo n.º 10
0
 def test_set_None_does_nothing_if_maas_id_file_does_not_exist(self):
     self.assertThat(self.maas_id_path, Not(FileExists()))
     env.set_maas_id(None)
Exemplo n.º 11
0
 def test_set_deletes_maas_id_file_if_argument_is_whitespace(self):
     with open(self.maas_id_path, "w") as fd:
         fd.write("This file will be deleted.")
     env.set_maas_id(string.whitespace)
     self.assertThat(self.maas_id_path, Not(FileExists()))
     self.assertIsNone(env.get_maas_id())
Exemplo n.º 12
0
 def test_set_writes_argument_to_maas_id_file(self):
     contents = factory.make_name("contents")
     env.set_maas_id(contents)
     self.assertThat(self.maas_id_path, FileContains(contents))
Exemplo n.º 13
0
 def setUp(self):
     super().setUp()
     self.maas_id_path = get_maas_data_path("maas_id")
     self.addCleanup(env.set_maas_id, None)
     env.set_maas_id(None)
Exemplo n.º 14
0
 def _setUp(self):
     super(MAASIDFixture, self)._setUp()
     self.addCleanup(env.set_maas_id, env.get_maas_id())
     env.set_maas_id(self.system_id)
Exemplo n.º 15
0
 def _setUp(self):
     super()._setUp()
     self.addCleanup(env.set_maas_id, env.get_maas_id())
     env.set_maas_id(self.system_id)