Ejemplo n.º 1
0
    def test_yields_configuration_when_machine_install_rackd_true(self):
        node = factory.make_Node(osystem="ubuntu", netboot=False)
        node.install_rackd = True
        proxy = "http://proxy.example.com/"
        configuration = generate_rack_controller_configuration(
            node, proxy=proxy
        )
        secret = "1234"
        Config.objects.set_config("rpc_shared_secret", secret)
        channel = version.get_maas_version_track_channel()
        maas_url = "http://%s:5240/MAAS" % get_maas_facing_server_host(
            node.get_boot_rack_controller()
        )
        cmd = "/bin/snap/maas init --mode rack"

        self.assertThat(
            dict(configuration),
            KeysEqual(
                {
                    "runcmd": [
                        "snap set system proxy.http=%s proxy.https=%s"
                        % (proxy, proxy),
                        f"snap install maas --channel={channel}",
                        "%s --maas-url %s --secret %s"
                        % (cmd, maas_url, secret),
                    ]
                }
            ),
        )
Ejemplo n.º 2
0
    def test_yields_configuration_with_ubuntu(self):
        tag = factory.make_Tag(name="wedge100")
        node = factory.make_Node(osystem="ubuntu", netboot=False)
        node.tags.add(tag)
        configuration = generate_rack_controller_configuration(
            node, proxy="http://proxy.example.com/"
        )
        secret = "1234"
        Config.objects.set_config("rpc_shared_secret", secret)
        channel = version.get_maas_version_track_channel()
        maas_url = "http://%s:5240/MAAS" % get_maas_facing_server_host(
            node.get_boot_rack_controller()
        )
        cmd = "/bin/snap/maas init --mode rack"

        self.assertThat(
            dict(configuration),
            KeysEqual(
                {
                    "runcmd": [
                        f"snap install maas --channel={channel}",
                        "%s --maas-url %s --secret %s"
                        % (cmd, maas_url, secret),
                    ]
                }
            ),
        )
Ejemplo n.º 3
0
def generate_rack_controller_configuration(node, proxy):
    """Generate cloud-init configuration to install the rack controller."""

    # FIXME: For now, we are using a tag ('switch') to deploy the rack
    # controller but once the switch model is complete we need to switch.
    # In the meatime we will leave it as is for testing purposes.
    node_tags = node.tag_names()
    # To determine this is a machine that's accessing the metadata after
    # initial deployment, we use 'node.netboot'. This flag is set to off after
    # curtin has installed the operating system and before the machine reboots
    # for the first time.
    if (node.netboot is False and node.osystem in ['ubuntu', 'ubuntu-core']
            and ('switch' in node_tags or 'wedge40' in node_tags
                 or 'wedge100' in node_tags or node.install_rackd is True)):
        maas_url = "http://%s:5240/MAAS" % get_maas_facing_server_host(
            node.get_boot_rack_controller())
        secret = Config.objects.get_config("rpc_shared_secret")
        source = get_maas_version_track_channel()
        yield "runcmd", [[
            'snap', 'set', 'system',
            'proxy.http=%s' % proxy,
            'proxy.https=%s' % proxy
        ], ['snap', 'install', 'maas', '--devmode',
            '--channel=%s' % source], ['systemctl', 'restart', 'snapd'],
                         ['export', 'PATH=$PATH'],
                         [
                             '/snap/bin/maas', 'init', '--mode', 'rack',
                             '--maas-url',
                             '%s' % maas_url, '--secret',
                             '%s' % secret
                         ]]
Ejemplo n.º 4
0
 def test_get_maas_version_track_channel(self):
     self.patch(
         version,
         "get_running_version").return_value = MAASVersion.from_string(
             self.version)
     result = version.get_maas_version_track_channel()
     self.assertEqual(result, self.output)
Ejemplo n.º 5
0
def generate_rack_controller_configuration(node, proxy):
    """Generate cloud-init configuration to install the rack controller."""

    # FIXME: For now, we are using a tag ('switch') to deploy the rack
    # controller but once the switch model is complete we need to switch.
    # In the meatime we will leave it as is for testing purposes.
    node_tags = node.tag_names()
    # To determine this is a machine that's accessing the metadata after
    # initial deployment, we use 'node.netboot'. This flag is set to off after
    # curtin has installed the operating system and before the machine reboots
    # for the first time.
    if (
        node.netboot is False
        and node.osystem in ["ubuntu", "ubuntu-core"]
        and (
            "switch" in node_tags
            or "wedge40" in node_tags
            or "wedge100" in node_tags
            or node.install_rackd is True
        )
    ):
        maas_url = "http://%s:5240/MAAS" % get_maas_facing_server_host(
            node.get_boot_rack_controller()
        )
        secret = Config.objects.get_config("rpc_shared_secret")
        source = get_maas_version_track_channel()
        yield "runcmd", [
            [
                "snap",
                "set",
                "system",
                f"proxy.http={proxy}",
                f"proxy.https={proxy}",
            ],
            ["snap", "install", "maas", f"--channel={source}"],
            ["systemctl", "restart", "snapd"],
            ["export", "PATH=$PATH"],
            [
                "/snap/bin/maas",
                "init",
                "--mode",
                "rack",
                "--maas-url",
                maas_url,
                "--secret",
                secret,
            ],
        ]
Ejemplo n.º 6
0
    def test_yields_configuration_when_machine_install_rackd_true(self):
        node = factory.make_Node(osystem='ubuntu', netboot=False)
        node.install_rackd = True
        configuration = generate_rack_controller_configuration(node)

        secret = '1234'
        Config.objects.set_config("rpc_shared_secret", secret)
        channel = version.get_maas_version_track_channel()
        maas_url = "http://%s:5240/MAAS" % get_maas_facing_server_host(
            node.get_boot_rack_controller())
        cmd = "/bin/snap/maas init --mode rack"

        self.assertThat(
            dict(configuration),
            KeysEqual({
                "runcmd": [
                    "snap install maas --devmode --channel=%s" % channel,
                    "%s --maas-url %s --secret %s" % (cmd, maas_url, secret),
                ]
            }))
Ejemplo n.º 7
0
def generate_rack_controller_configuration(node):
    """Generate cloud-init configuration to install the rack controller."""

    # FIXME: For now, we are using a tag ('switch') to deploy the rack
    # controller but once the switch model is complete we need to switch.
    # In the meatime we will leave it as is for testing purposes.
    node_tags = node.tag_names()
    # To determine this is a machine that's accessing the metadata after
    # initial deployment, we use 'node.netboot'. This flag is set to off after
    # curtin has installed the operating system and before the machine reboots
    # for the first time.
    if (node.netboot is False and node.osystem in ['ubuntu', 'ubuntu-core']
            and ('switch' in node_tags or 'wedge40' in node_tags
                 or 'wedge100' in node_tags)):
        maas_url = "http://%s:5240/MAAS" % get_maas_facing_server_host(
            node.get_boot_rack_controller())
        secret = Config.objects.get_config("rpc_shared_secret")
        source = get_maas_version_track_channel()
        yield "runcmd", [
            "snap install maas --devmode --channel=%s" % source,
            "/snap/bin/maas init --mode rack --maas-url %s --secret %s" %
            (maas_url, secret)
        ]
Ejemplo n.º 8
0
 def test_get_maas_version_track_channel(self):
     mock = self.patch(version, "get_maas_version")
     mock.return_value = self.version
     result = version.get_maas_version_track_channel()
     self.assertEqual(result, self.output)