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
=== modified file 'src/maasserver/compose_preseed.py'
--- src/maasserver/compose_preseed.py 2017-03-29 21:13:51 +0000
+++ src/maasserver/compose_preseed.py 2017-06-16 09:11:46 +0000
@@ -31,17 +31,17 @@
31RSYSLOG_PORT = 51431RSYSLOG_PORT = 514
3232
3333
34def get_apt_proxy_for_node(node):34def get_apt_proxy(rack_controller=None):
35 """Return the APT proxy for the `node`."""35 """Return the APT proxy for the `rack_controller`."""
36 if Config.objects.get_config("enable_http_proxy"):36 if Config.objects.get_config("enable_http_proxy"):
37 http_proxy = Config.objects.get_config("http_proxy")37 http_proxy = Config.objects.get_config("http_proxy")
38 if (http_proxy is not None and len(http_proxy) > 0 and38 if http_proxy is not None:
39 not http_proxy.isspace()):39 http_proxy = http_proxy.strip()
40 if http_proxy:
40 return http_proxy41 return http_proxy
41 else:42 else:
42 return compose_URL(43 return compose_URL(
43 "http://:8000/", get_maas_facing_server_host(44 "http://:8000/", get_maas_facing_server_host(rack_controller))
44 node.get_boot_rack_controller()))
45 else:45 else:
46 return None46 return None
4747
@@ -58,7 +58,7 @@
58 arch = node.split_arch()[0]58 arch = node.split_arch()[0]
59 archive = PackageRepository.objects.get_default_archive(arch)59 archive = PackageRepository.objects.get_default_archive(arch)
60 repositories = PackageRepository.objects.get_additional_repositories(arch)60 repositories = PackageRepository.objects.get_additional_repositories(arch)
61 apt_proxy = get_apt_proxy_for_node(node)61 apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
6262
63 # Process the default Ubuntu Archives or Mirror.63 # Process the default Ubuntu Archives or Mirror.
64 archives = {}64 archives = {}
@@ -225,7 +225,7 @@
225 }225 }
226 # Add the system configuration information.226 # Add the system configuration information.
227 config.update(get_system_info())227 config.update(get_system_info())
228 apt_proxy = get_apt_proxy_for_node(node)228 apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
229 if apt_proxy:229 if apt_proxy:
230 config['apt_proxy'] = apt_proxy230 config['apt_proxy'] = apt_proxy
231 # Add APT configuration for new cloud-init (>= 0.7.7-17)231 # Add APT configuration for new cloud-init (>= 0.7.7-17)
@@ -313,7 +313,7 @@
313 }313 }
314 # Add the system configuration information.314 # Add the system configuration information.
315 cloud_config.update(get_system_info())315 cloud_config.update(get_system_info())
316 apt_proxy = get_apt_proxy_for_node(node)316 apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
317 if apt_proxy:317 if apt_proxy:
318 cloud_config['apt_proxy'] = apt_proxy318 cloud_config['apt_proxy'] = apt_proxy
319 # Add APT configuration for new cloud-init (>= 0.7.7-17)319 # Add APT configuration for new cloud-init (>= 0.7.7-17)
320320
=== modified file 'src/maasserver/preseed.py'
--- src/maasserver/preseed.py 2017-06-13 10:54:20 +0000
+++ src/maasserver/preseed.py 2017-06-16 09:11:46 +0000
@@ -33,6 +33,7 @@
33from maasserver.compose_preseed import (33from maasserver.compose_preseed import (
34 compose_cloud_init_preseed,34 compose_cloud_init_preseed,
35 compose_preseed,35 compose_preseed,
36 get_apt_proxy,
36 get_archive_config,37 get_archive_config,
37 get_system_info,38 get_system_info,
38 RSYSLOG_PORT,39 RSYSLOG_PORT,
@@ -111,13 +112,7 @@
111 :return: The rendered enlistment user-data string.112 :return: The rendered enlistment user-data string.
112 :rtype: unicode.113 :rtype: unicode.
113 """114 """
114 server_host = get_maas_facing_server_host(rack_controller=rack_controller)115 http_proxy = get_apt_proxy(rack_controller=rack_controller)
115 http_proxy = None
116 if Config.objects.get_config('enable_http_proxy'):
117 if Config.objects.get_config('http_proxy'):
118 http_proxy = Config.objects.get_config('http_proxy')
119 elif server_host:
120 http_proxy = "http://%s:8000/" % server_host
121 enlist_userdata = render_enlistment_preseed(116 enlist_userdata = render_enlistment_preseed(
122 USERDATA_TYPE.ENLIST, rack_controller=rack_controller)117 USERDATA_TYPE.ENLIST, rack_controller=rack_controller)
123 config = get_system_info()118 config = get_system_info()
124119
=== modified file 'src/maasserver/tests/test_compose_preseed.py'
--- src/maasserver/tests/test_compose_preseed.py 2017-03-29 22:00:38 +0000
+++ src/maasserver/tests/test_compose_preseed.py 2017-06-16 09:11:46 +0000
@@ -9,7 +9,7 @@
99
10from maasserver.compose_preseed import (10from maasserver.compose_preseed import (
11 compose_preseed,11 compose_preseed,
12 get_apt_proxy_for_node,12 get_apt_proxy,
13)13)
14from maasserver.enum import (14from maasserver.enum import (
15 NODE_STATUS,15 NODE_STATUS,
@@ -89,7 +89,7 @@
89 interface=True, status=NODE_STATUS.COMMISSIONING)89 interface=True, status=NODE_STATUS.COMMISSIONING)
90 Config.objects.set_config("enable_http_proxy", self.enable)90 Config.objects.set_config("enable_http_proxy", self.enable)
91 Config.objects.set_config("http_proxy", self.http_proxy)91 Config.objects.set_config("http_proxy", self.http_proxy)
92 actual = get_apt_proxy_for_node(node)92 actual = get_apt_proxy(node.get_boot_rack_controller())
93 self.assertEqual(self.result, actual)93 self.assertEqual(self.result, actual)
9494
9595
@@ -180,7 +180,7 @@
180 nic.vlan.dhcp_on = True180 nic.vlan.dhcp_on = True
181 nic.vlan.primary_rack = rack_controller181 nic.vlan.primary_rack = rack_controller
182 nic.vlan.save()182 nic.vlan.save()
183 apt_proxy = get_apt_proxy_for_node(node)183 apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
184 preseed = yaml.safe_load(184 preseed = yaml.safe_load(
185 compose_preseed(PRESEED_TYPE.COMMISSIONING, node))185 compose_preseed(PRESEED_TYPE.COMMISSIONING, node))
186 self.assertIn('datasource', preseed)186 self.assertIn('datasource', preseed)
@@ -365,7 +365,7 @@
365 nic.vlan.primary_rack = rack_controller365 nic.vlan.primary_rack = rack_controller
366 nic.vlan.save()366 nic.vlan.save()
367 self.useFixture(RunningClusterRPCFixture())367 self.useFixture(RunningClusterRPCFixture())
368 apt_proxy = get_apt_proxy_for_node(node)368 apt_proxy = get_apt_proxy(node.get_boot_rack_controller())
369 preseed = yaml.safe_load(369 preseed = yaml.safe_load(
370 compose_preseed(PRESEED_TYPE.CURTIN, node))370 compose_preseed(PRESEED_TYPE.CURTIN, node))
371371