Пример #1
0
 def assertAptConfig(self, config, apt_proxy):
     self.assertThat(
         config,
         ContainsDict({
             'apt':
             ContainsDict({
                 'preserve_sources_list':
                 Equals(False),
                 'primary':
                 MatchesListwise([
                     MatchesDict({
                         "arches":
                         Equals(["default"]),
                         "uri":
                         Equals(PackageRepository.get_main_archive().url),
                     }),
                 ]),
                 'proxy':
                 Equals(apt_proxy),
                 'security':
                 MatchesListwise([
                     MatchesDict({
                         "arches":
                         Equals(["default"]),
                         "uri":
                         Equals(PackageRepository.get_main_archive().url),
                     }),
                 ]),
             })
         }))
Пример #2
0
def get_old_archive_config():
    """Return the system info which includes the APT mirror information."""
    # Deprecated in cloud-init 0.7.8 in favor of the apt configuration format
    # generated by get_archive_config. This is still provided as old releases
    # (Precise, Trusty) have an older version of cloud-init which only reads
    # this format.
    return {
        "system_info": {
            "package_mirrors": [
                {
                    "arches": ["i386", "amd64"],
                    "search": {
                        "primary": [PackageRepository.get_main_archive().url],
                        "security": [PackageRepository.get_main_archive().url],
                    },
                    "failsafe": {
                        "primary": "http://archive.ubuntu.com/ubuntu",
                        "security": "http://security.ubuntu.com/ubuntu",
                    },
                },
                {
                    "arches": ["default"],
                    "search": {
                        "primary": [PackageRepository.get_ports_archive().url],
                        "security":
                        [PackageRepository.get_ports_archive().url],
                    },
                    "failsafe": {
                        "primary": "http://ports.ubuntu.com/ubuntu-ports",
                        "security": "http://ports.ubuntu.com/ubuntu-ports",
                    },
                },
            ]
        }
    }
Пример #3
0
def get_system_info():
    """Return the system info which includes the APT mirror information."""
    return {
        "system_info": {
            "package_mirrors": [
                {
                    "arches": ["i386", "amd64"],
                    "search": {
                        "primary": [
                            PackageRepository.get_main_archive().url],
                        "security": [
                            PackageRepository.get_main_archive().url],
                    },
                    "failsafe": {
                        "primary": "http://archive.ubuntu.com/ubuntu",
                        "security": "http://security.ubuntu.com/ubuntu",
                    }
                },
                {
                    "arches": ["default"],
                    "search": {
                        "primary": [
                            PackageRepository.get_ports_archive().url],
                        "security": [
                            PackageRepository.get_ports_archive().url],
                    },
                    "failsafe": {
                        "primary": "http://ports.ubuntu.com/ubuntu-ports",
                        "security": "http://ports.ubuntu.com/ubuntu-ports",
                    }
                },
            ]
        }
    }
Пример #4
0
 def assertSystemInfo(self, config):
     self.assertThat(
         config,
         ContainsDict({
             "system_info":
             MatchesDict({
                 "package_mirrors":
                 MatchesListwise([
                     MatchesDict({
                         "arches":
                         Equals(["i386", "amd64"]),
                         "search":
                         MatchesDict({
                             "primary":
                             Equals([
                                 PackageRepository.get_main_archive().url
                             ]),
                             "security":
                             Equals([
                                 PackageRepository.get_main_archive().url
                             ]),
                         }),
                         "failsafe":
                         MatchesDict({
                             "primary":
                             Equals("http://archive.ubuntu.com/ubuntu"),
                             "security":
                             Equals("http://security.ubuntu.com/ubuntu"),
                         }),
                     }),
                     MatchesDict({
                         "arches":
                         Equals(["default"]),
                         "search":
                         MatchesDict({
                             "primary":
                             Equals([
                                 PackageRepository.get_ports_archive().url
                             ]),
                             "security":
                             Equals([
                                 PackageRepository.get_ports_archive().url
                             ]),
                         }),
                         "failsafe":
                         MatchesDict({
                             "primary":
                             Equals("http://ports.ubuntu.com/ubuntu-ports"),
                             "security":
                             Equals("http://ports.ubuntu.com/ubuntu-ports"),
                         }),
                     }),
                 ])
             })
         }),
     )
Пример #5
0
 def test_compose_enlistment_preseed_disables_suites(self):
     default = PackageRepository.get_main_archive()
     default.disabled_pockets = ["security", "updates", "backports"]
     default.save()
     rack_controller = factory.make_RackController()
     url = factory.make_simple_http_url()
     request = make_HttpRequest()
     preseed = yaml.safe_load(
         compose_enlistment_preseed(
             request,
             rack_controller,
             {
                 "metadata_enlist_url": url,
                 "syslog_host_port": url
             },
         ))
     self.assertItemsEqual(
         set([
             "#",
             "deb",
             "deb-src",
             "$PRIMARY",
             "$RELEASE",
             "multiverse",
             "restricted",
             "universe",
             "main",
         ]),
         set(preseed["apt"]["sources_list"].split()),
     )
Пример #6
0
def get_node_deprecated_preseed_context():
    """Return the node-dependent context dictionary to be used to render
    preseed template. This includes all the context variables that have
    been deprecated, but allows for backwards compatibility for those
    preseeds that still contain old variables.

    :return: The context dictionary.
    :rtype: dict.
    """
    main_archive_hostname, main_archive_directory = get_netloc_and_path(
        PackageRepository.get_main_archive().url)
    ports_archive_hostname, ports_archive_directory = get_netloc_and_path(
        PackageRepository.get_ports_archive().url)

    return {
        "main_archive_hostname": main_archive_hostname,
        "main_archive_directory": main_archive_directory,
        "ports_archive_hostname": ports_archive_hostname,
        "ports_archive_directory": ports_archive_directory,
        "enable_http_proxy": Config.objects.get_config("enable_http_proxy"),
    }
Пример #7
0
    def test_settings_ubuntu_POST(self):
        self.client.login(user=factory.make_admin())
        new_main_archive = 'http://test.example.com/archive'
        new_ports_archive = 'http://test2.example.com/archive'
        response = self.client.post(
            reverse('settings_general'),
            get_prefixed_form_data(prefix='ubuntu',
                                   data={
                                       'main_archive': new_main_archive,
                                       'ports_archive': new_ports_archive,
                                   }))

        self.assertEqual(http.client.FOUND, response.status_code,
                         response.content)
        self.assertEqual((
            new_main_archive,
            new_ports_archive,
        ), (
            PackageRepository.get_main_archive().url,
            PackageRepository.get_ports_archive().url,
        ))
Пример #8
0
    def test_get_archive_mirrors_with_ports_archive_set(self):
        ports_archive = yield deferToDatabase(
            lambda: PackageRepository.get_ports_archive())
        url = factory.make_parsed_url(scheme='http')
        ports_archive.url = url.geturl()
        yield deferToDatabase(transactional(ports_archive.save))

        response = yield call_responder(Region(), GetArchiveMirrors, {})

        self.assertEqual(
            {"main": urlparse("http://archive.ubuntu.com/ubuntu"),
             "ports": url},
            response)
Пример #9
0
def get_enlist_archive_config(apt_proxy=None):
    default = PackageRepository.get_main_archive()
    ports = PackageRepository.get_ports_archive()
    # Process the default Ubuntu Archives or Mirror.
    archives = {
        'apt': {
            'preserve_sources_list':
            False,
            'primary': [
                {
                    'arches': ['amd64', 'i386'],
                    'uri': default.url
                },
                {
                    'arches': ['default'],
                    'uri': ports.url
                },
            ],
            'security': [
                {
                    'arches': ['amd64', 'i386'],
                    'uri': default.url
                },
                {
                    'arches': ['default'],
                    'uri': ports.url
                },
            ],
        },
    }
    if apt_proxy:
        archives['apt']['proxy'] = apt_proxy
    if default.key:
        archives['apt']['sources'] = {'default_key': {'key': default.key}}
    if ports.key:
        archives['apt']['sources'] = {'ports_key': {'key': ports.key}}

    return archives
Пример #10
0
 def test_compose_enlistment_preseed_disables_components(self):
     default = PackageRepository.get_main_archive()
     default.disabled_components = ['restricted', 'multiverse']
     default.save()
     rack_controller = factory.make_RackController()
     url = factory.make_simple_http_url()
     request = make_HttpRequest()
     preseed = yaml.safe_load(
         compose_enlistment_preseed(request, rack_controller, {
             'metadata_enlist_url': url,
             'syslog_host_port': url,
         }))
     self.assertNotIn('restricted', preseed['apt']['sources_list'])
     self.assertNotIn('multiverse', preseed['apt']['sources_list'])
Пример #11
0
    def test_settings_ubuntu_POST(self):
        self.client.login(user=factory.make_admin())
        new_main_archive = "http://test.example.com/archive"
        new_ports_archive = "http://test2.example.com/archive"
        response = self.client.post(
            reverse("settings_general"),
            get_prefixed_form_data(
                prefix="ubuntu",
                data={
                    "main_archive": new_main_archive,
                    "ports_archive": new_ports_archive,
                },
            ),
        )

        self.assertEqual(http.client.FOUND, response.status_code,
                         response.content)
        self.assertEqual(
            (new_main_archive, new_ports_archive),
            (
                PackageRepository.get_main_archive().url,
                PackageRepository.get_ports_archive().url,
            ),
        )
Пример #12
0
 def test_set_ports_archive_overrides_to_package_repository(self):
     self.become_admin()
     ports_archive = factory.make_url(scheme="http")
     response = self.client.post(reverse('maas_handler'), {
         "op": "set_config",
         "name": "ports_archive",
         "value": ports_archive,
     })
     self.assertThat(
         response,
         MatchesAll(
             # An HTTP 200 response,
             MatchesStructure(status_code=Equals(http.client.OK),
                              content=Equals(b"OK")), ))
     self.assertThat(PackageRepository.get_ports_archive().url,
                     Equals(ports_archive))
 def test_compose_enlistment_preseed_disables_components(self):
     default = PackageRepository.get_main_archive()
     default.disabled_components = ["restricted", "multiverse"]
     default.save()
     rack_controller = factory.make_RackController()
     url = factory.make_simple_http_url()
     request = make_HttpRequest()
     preseed = yaml.safe_load(
         compose_enlistment_preseed(
             request,
             rack_controller,
             {"metadata_enlist_url": url, "syslog_host_port": url},
         )
     )
     self.assertNotIn("restricted", preseed["apt"]["sources_list"])
     self.assertNotIn("multiverse", preseed["apt"]["sources_list"])
Пример #14
0
 def test_compose_enlistment_preseed_disables_suites(self):
     default = PackageRepository.get_main_archive()
     default.disabled_pockets = ['security', 'updates', 'backports']
     default.save()
     rack_controller = factory.make_RackController()
     url = factory.make_simple_http_url()
     request = make_HttpRequest()
     preseed = yaml.safe_load(
         compose_enlistment_preseed(request, rack_controller, {
             'metadata_enlist_url': url,
             'syslog_host_port': url,
         }))
     self.assertItemsEqual(
         set([
             '#', 'deb', 'deb-src', '$PRIMARY', '$RELEASE', 'multiverse',
             'restricted', 'universe', 'main'
         ]), set(preseed['apt']['sources_list'].split()))
Пример #15
0
 def test_compose_enlistment_preseed(self):
     rack_controller = factory.make_RackController()
     url = factory.make_simple_http_url()
     request = make_HttpRequest()
     apt_proxy = get_apt_proxy(request, rack_controller)
     preseed = yaml.safe_load(
         compose_enlistment_preseed(
             request,
             rack_controller,
             {
                 "metadata_enlist_url": url,
                 "syslog_host_port": url
             },
         ))
     self.assertDictEqual({"MAAS": {
         "metadata_url": url
     }}, preseed["datasource"])
     self.assertTrue(preseed["manage_etc_hosts"])
     self.assertDictEqual({"remotes": {"maas": url}}, preseed["rsyslog"])
     self.assertDictEqual(
         {
             "delay": "now",
             "mode": "poweroff",
             "timeout": 1800,
             "condition": "test ! -e /tmp/block-poweroff",
         },
         preseed["power_state"],
     )
     self.assertItemsEqual(
         [
             "python3-yaml",
             "python3-oauthlib",
             "freeipmi-tools",
             "ipmitool",
             "sshpass",
             "archdetect-deb",
             "jq",
         ],
         preseed["packages"],
     )
     default = PackageRepository.get_main_archive().url
     ports = PackageRepository.get_ports_archive().url
     self.assertThat(
         preseed,
         ContainsDict({
             "apt":
             ContainsDict({
                 "preserve_sources_list":
                 Equals(False),
                 "primary":
                 MatchesListwise([
                     MatchesDict({
                         "arches": Equals(["amd64", "i386"]),
                         "uri": Equals(default),
                     }),
                     MatchesDict({
                         "arches": Equals(["default"]),
                         "uri": Equals(ports),
                     }),
                 ]),
                 "proxy":
                 Equals(apt_proxy),
                 "security":
                 MatchesListwise([
                     MatchesDict({
                         "arches": Equals(["amd64", "i386"]),
                         "uri": Equals(default),
                     }),
                     MatchesDict({
                         "arches": Equals(["default"]),
                         "uri": Equals(ports),
                     }),
                 ]),
             })
         }),
     )
Пример #16
0
 def test_default_repositories_cannot_be_deleted(self):
     with ExpectedException(ValidationError):
         PackageRepository.get_main_archive().delete()
     with ExpectedException(ValidationError):
         PackageRepository.get_ports_archive().delete()
Пример #17
0
 def test_compose_enlistment_preseed(self):
     rack_controller = factory.make_RackController()
     url = factory.make_simple_http_url()
     request = make_HttpRequest()
     apt_proxy = get_apt_proxy(request, rack_controller)
     preseed = yaml.safe_load(
         compose_enlistment_preseed(request, rack_controller, {
             'metadata_enlist_url': url,
             'syslog_host_port': url,
         }))
     self.assertDictEqual({'MAAS': {
         'metadata_url': url
     }}, preseed['datasource'])
     self.assertTrue(preseed['manage_etc_hosts'])
     self.assertDictEqual({'remotes': {'maas': url}}, preseed['rsyslog'])
     self.assertDictEqual(
         {
             'delay': 'now',
             'mode': 'poweroff',
             'timeout': 1800,
             'condition': 'test ! -e /tmp/block-poweroff',
         }, preseed['power_state'])
     self.assertItemsEqual([
         'python3-yaml', 'python3-oauthlib', 'freeipmi-tools', 'ipmitool',
         'sshpass', 'archdetect-deb', 'jq'
     ], preseed['packages'])
     default = PackageRepository.get_main_archive().url
     ports = PackageRepository.get_ports_archive().url
     self.assertThat(
         preseed,
         ContainsDict({
             'apt':
             ContainsDict({
                 'preserve_sources_list':
                 Equals(False),
                 'primary':
                 MatchesListwise([
                     MatchesDict({
                         "arches": Equals(["amd64", "i386"]),
                         "uri": Equals(default),
                     }),
                     MatchesDict({
                         "arches": Equals(["default"]),
                         "uri": Equals(ports),
                     }),
                 ]),
                 'proxy':
                 Equals(apt_proxy),
                 'security':
                 MatchesListwise([
                     MatchesDict({
                         "arches": Equals(["amd64", "i386"]),
                         "uri": Equals(default),
                     }),
                     MatchesDict({
                         "arches": Equals(["default"]),
                         "uri": Equals(ports),
                     }),
                 ]),
             })
         }))
Пример #18
0
def get_enlist_archive_config(apt_proxy=None):
    default = PackageRepository.get_main_archive()
    ports = PackageRepository.get_ports_archive()
    # Process the default Ubuntu Archives or Mirror.
    archives = {
        "apt": {
            "preserve_sources_list":
            False,
            "primary": [
                {
                    "arches": ["amd64", "i386"],
                    "uri": default.url
                },
                {
                    "arches": ["default"],
                    "uri": ports.url
                },
            ],
            "security": [
                {
                    "arches": ["amd64", "i386"],
                    "uri": default.url
                },
                {
                    "arches": ["default"],
                    "uri": ports.url
                },
            ],
        }
    }
    if apt_proxy:
        archives["apt"]["proxy"] = apt_proxy
    if default.key:
        archives["apt"]["sources"] = {"default_key": {"key": default.key}}
    if ports.key:
        archives["apt"]["sources"] = {"ports_key": {"key": ports.key}}

    # Collect the list of all things to disable. Since we do not know the
    # architecture during enlistment if a suite or component is disabled on
    # default or ports it will be disabled on both during enlistment.
    disabled_suites = set()
    disabled_components = set()
    disable_sources = default.disable_sources or ports.disable_sources
    for repo in [default, ports]:
        disabled_suites = disabled_suites.union(repo.disabled_pockets)
        disabled_components = disabled_components.union(
            repo.disabled_components)

    components = " ".join(
        disabled_components.symmetric_difference(default.KNOWN_COMPONENTS))
    archives["apt"]["sources_list"] = "deb $PRIMARY $RELEASE %s\n" % components
    if disable_sources:
        archives["apt"]["sources_list"] += "# "
    archives["apt"]["sources_list"] += ("deb-src $PRIMARY $RELEASE %s\n" %
                                        components)
    for suite in ["updates", "backports"]:
        if suite not in disabled_suites:
            archives["apt"][
                "sources_list"] += "deb $PRIMARY $RELEASE-%s %s\n" % (
                    suite, components)
            if disable_sources:
                archives["apt"]["sources_list"] += "# "
            archives["apt"][
                "sources_list"] += "deb-src $PRIMARY $RELEASE-%s %s\n" % (
                    suite, components)
    if "security" not in disabled_suites:
        archives["apt"]["sources_list"] += (
            "deb $SECURITY $RELEASE-security %s\n" % components)
        if disable_sources:
            archives["apt"]["sources_list"] += "# "
        archives["apt"]["sources_list"] += (
            "deb-src $SECURITY $RELEASE-security %s\n" % components)

    return archives
Пример #19
0
def get_enlist_archive_config(apt_proxy=None):
    default = PackageRepository.get_main_archive()
    ports = PackageRepository.get_ports_archive()
    # Process the default Ubuntu Archives or Mirror.
    archives = {
        'apt': {
            'preserve_sources_list': False,
            'primary': [
                {
                    'arches': ['amd64', 'i386'],
                    'uri': default.url
                },
                {
                    'arches': ['default'],
                    'uri': ports.url
                },
            ],
            'security': [
                {
                    'arches': ['amd64', 'i386'],
                    'uri': default.url
                },
                {
                    'arches': ['default'],
                    'uri': ports.url
                },
            ],
        },
    }
    if apt_proxy:
        archives['apt']['proxy'] = apt_proxy
    if default.key:
        archives['apt']['sources'] = {
            'default_key': {
                'key': default.key
            }
        }
    if ports.key:
        archives['apt']['sources'] = {
            'ports_key': {
                'key': ports.key
            }
        }

    # Collect the list of all things to disable. Since we do not know the
    # architecture during enlistment if a suite or component is disabled on
    # default or ports it will be disabled on both during enlistment.
    disabled_suites = set()
    disabled_components = set()
    disable_sources = default.disable_sources or ports.disable_sources
    for repo in [default, ports]:
        disabled_suites = disabled_suites.union(repo.disabled_pockets)
        disabled_components = disabled_components.union(
            repo.disabled_components)

    components = ' '.join(disabled_components.symmetric_difference(
        default.KNOWN_COMPONENTS))
    archives['apt']['sources_list'] = 'deb $PRIMARY $RELEASE %s\n' % components
    if disable_sources:
        archives['apt']['sources_list'] += '# '
    archives['apt']['sources_list'] += (
        'deb-src $PRIMARY $RELEASE %s\n' % components)
    for suite in ['updates', 'backports']:
        if suite not in disabled_suites:
            archives['apt']['sources_list'] += (
                'deb $PRIMARY $RELEASE-%s %s\n' % (suite, components))
            if disable_sources:
                archives['apt']['sources_list'] += '# '
            archives['apt']['sources_list'] += (
                'deb-src $PRIMARY $RELEASE-%s %s\n' % (suite, components))
    if 'security' not in disabled_suites:
        archives['apt']['sources_list'] += (
            'deb $SECURITY $RELEASE-security %s\n' % components)
        if disable_sources:
            archives['apt']['sources_list'] += '# '
        archives['apt']['sources_list'] += (
            'deb-src $SECURITY $RELEASE-security %s\n' % components)

    return archives