Merge lp:~bjornt/maas/get-apt-proxy into lp:~maas-committers/maas/trunk

Proposed by Björn Tillenius
Status: Merged
Approved by: Björn Tillenius
Approved revision: 6070
Merged at revision: 6090
Proposed branch: lp:~bjornt/maas/get-apt-proxy
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 120 lines (+15/-20)
3 files modified
src/maasserver/compose_preseed.py (+9/-9)
src/maasserver/preseed.py (+2/-7)
src/maasserver/tests/test_compose_preseed.py (+4/-4)
To merge this branch: bzr merge lp:~bjornt/maas/get-apt-proxy
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+325756@code.launchpad.net

Description of the change

Factor out getting the APT proxy.

The same logic was duplicated in two places. I'm going to change the
logic later, so having it in one place makes it easier.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good to me!

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (125.6 KiB)

The attempt to merge lp:~bjornt/maas/get-apt-proxy into lp:maas failed. Below is the output from the failed tests.

Hit:1 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:3 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Fetched 306 kB in 0s (661 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common isc-dhcp-server libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libnss-wrapper libpq-dev make nodejs-legacy npm postgresql psmisc pxelinux python3-all python3-apt python3-attr python3-bson python3-convoy python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-netaddr python3-netifaces python3-novaclient python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
psmisc is already the newest version (22.21-2.1build1).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7.18-1).
python-netifaces is already the newest version (0.10.4-0.1build2).
python-p...

Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (2.0 MiB)

The attempt to merge lp:~bjornt/maas/get-apt-proxy into lp:maas failed. Below is the output from the failed tests.

Hit:1 http://security.ubuntu.com/ubuntu xenial-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
Hit:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Hit:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common isc-dhcp-server libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libnss-wrapper libpq-dev make nodejs-legacy npm postgresql psmisc pxelinux python3-all python3-apt python3-attr python3-bson python3-convoy python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-netaddr python3-netifaces python3-novaclient python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
psmisc is already the newest version (22.21-2.1build1).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7.18-1).
python-netifaces is already the newest version (0.10.4-0.1build2).
python-psycopg2 is already the newest version (2.6.1-1build2).
python-simplejson is already the newest version (3.8.1-1ubuntu2).
python-tem...

lp:~bjornt/maas/get-apt-proxy updated
6070. By Björn Tillenius

Fix imports.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/compose_preseed.py'
2--- src/maasserver/compose_preseed.py 2017-03-29 21:13:51 +0000
3+++ src/maasserver/compose_preseed.py 2017-06-16 09:11:46 +0000
4@@ -31,17 +31,17 @@
5 RSYSLOG_PORT = 514
6
7
8-def get_apt_proxy_for_node(node):
9- """Return the APT proxy for the `node`."""
10+def get_apt_proxy(rack_controller=None):
11+ """Return the APT proxy for the `rack_controller`."""
12 if Config.objects.get_config("enable_http_proxy"):
13 http_proxy = Config.objects.get_config("http_proxy")
14- if (http_proxy is not None and len(http_proxy) > 0 and
15- not http_proxy.isspace()):
16+ if http_proxy is not None:
17+ http_proxy = http_proxy.strip()
18+ if http_proxy:
19 return http_proxy
20 else:
21 return compose_URL(
22- "http://:8000/", get_maas_facing_server_host(
23- node.get_boot_rack_controller()))
24+ "http://:8000/", get_maas_facing_server_host(rack_controller))
25 else:
26 return None
27
28@@ -58,7 +58,7 @@
29 arch = node.split_arch()[0]
30 archive = PackageRepository.objects.get_default_archive(arch)
31 repositories = PackageRepository.objects.get_additional_repositories(arch)
32- apt_proxy = get_apt_proxy_for_node(node)
33+ apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
34
35 # Process the default Ubuntu Archives or Mirror.
36 archives = {}
37@@ -225,7 +225,7 @@
38 }
39 # Add the system configuration information.
40 config.update(get_system_info())
41- apt_proxy = get_apt_proxy_for_node(node)
42+ apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
43 if apt_proxy:
44 config['apt_proxy'] = apt_proxy
45 # Add APT configuration for new cloud-init (>= 0.7.7-17)
46@@ -313,7 +313,7 @@
47 }
48 # Add the system configuration information.
49 cloud_config.update(get_system_info())
50- apt_proxy = get_apt_proxy_for_node(node)
51+ apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
52 if apt_proxy:
53 cloud_config['apt_proxy'] = apt_proxy
54 # Add APT configuration for new cloud-init (>= 0.7.7-17)
55
56=== modified file 'src/maasserver/preseed.py'
57--- src/maasserver/preseed.py 2017-06-13 10:54:20 +0000
58+++ src/maasserver/preseed.py 2017-06-16 09:11:46 +0000
59@@ -33,6 +33,7 @@
60 from maasserver.compose_preseed import (
61 compose_cloud_init_preseed,
62 compose_preseed,
63+ get_apt_proxy,
64 get_archive_config,
65 get_system_info,
66 RSYSLOG_PORT,
67@@ -111,13 +112,7 @@
68 :return: The rendered enlistment user-data string.
69 :rtype: unicode.
70 """
71- server_host = get_maas_facing_server_host(rack_controller=rack_controller)
72- http_proxy = None
73- if Config.objects.get_config('enable_http_proxy'):
74- if Config.objects.get_config('http_proxy'):
75- http_proxy = Config.objects.get_config('http_proxy')
76- elif server_host:
77- http_proxy = "http://%s:8000/" % server_host
78+ http_proxy = get_apt_proxy(rack_controller=rack_controller)
79 enlist_userdata = render_enlistment_preseed(
80 USERDATA_TYPE.ENLIST, rack_controller=rack_controller)
81 config = get_system_info()
82
83=== modified file 'src/maasserver/tests/test_compose_preseed.py'
84--- src/maasserver/tests/test_compose_preseed.py 2017-03-29 22:00:38 +0000
85+++ src/maasserver/tests/test_compose_preseed.py 2017-06-16 09:11:46 +0000
86@@ -9,7 +9,7 @@
87
88 from maasserver.compose_preseed import (
89 compose_preseed,
90- get_apt_proxy_for_node,
91+ get_apt_proxy,
92 )
93 from maasserver.enum import (
94 NODE_STATUS,
95@@ -89,7 +89,7 @@
96 interface=True, status=NODE_STATUS.COMMISSIONING)
97 Config.objects.set_config("enable_http_proxy", self.enable)
98 Config.objects.set_config("http_proxy", self.http_proxy)
99- actual = get_apt_proxy_for_node(node)
100+ actual = get_apt_proxy(node.get_boot_rack_controller())
101 self.assertEqual(self.result, actual)
102
103
104@@ -180,7 +180,7 @@
105 nic.vlan.dhcp_on = True
106 nic.vlan.primary_rack = rack_controller
107 nic.vlan.save()
108- apt_proxy = get_apt_proxy_for_node(node)
109+ apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
110 preseed = yaml.safe_load(
111 compose_preseed(PRESEED_TYPE.COMMISSIONING, node))
112 self.assertIn('datasource', preseed)
113@@ -365,7 +365,7 @@
114 nic.vlan.primary_rack = rack_controller
115 nic.vlan.save()
116 self.useFixture(RunningClusterRPCFixture())
117- apt_proxy = get_apt_proxy_for_node(node)
118+ apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
119 preseed = yaml.safe_load(
120 compose_preseed(PRESEED_TYPE.CURTIN, node))
121