Merge lp:~psivaa/uci-engine/django-in-mthood into lp:uci-engine/mthood

Proposed by Para Siva
Status: Merged
Merged at revision: 417
Proposed branch: lp:~psivaa/uci-engine/django-in-mthood
Merge into: lp:uci-engine/mthood
Prerequisite: lp:~psivaa/uci-engine/lander-jenkins-plugin
Diff against target: 204 lines (+60/-5)
5 files modified
charms/precise/python-django/config.yaml (+8/-0)
charms/precise/python-django/hooks/hooks.py (+37/-3)
juju-deployer/deploy.py (+11/-2)
juju-deployer/ppa-assigner.yaml.tmpl (+2/-0)
juju-deployer/ticket-system.yaml.tmpl (+2/-0)
To merge this branch: bzr merge lp:~psivaa/uci-engine/django-in-mthood
Reviewer Review Type Date Requested Status
Canonical CI Engineering Pending
Review via email: mp+219118@code.launchpad.net

Commit message

Fixes the python-django installation related issues in mthood private cloud. This completes the changes needed for the deployment in the private cloud.

Description of the change

Fixes the python-django installation related issues in mthood private cloud. This completes the changes needed for the deployment in the private cloud.

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) wrote :

On 05/11/2014 07:07 AM, Parameswaran Sivatharman wrote:

> === modified file 'charms/precise/python-django/hooks/hooks.py'
> @@ -347,7 +348,6 @@
> remote_host = run("relation-get private-address")
> return remote_host
>
> -
> def get_unit_host():

check out the deletion of that line. I suspect that might cause a pep8
warning. functions need 2 blank lines between them.

> @@ -365,6 +365,15 @@
> with open(destination, 'w') as inject_file:
> inject_file.write(str(template))
>
> +def import_ci_ppa_keys():

ditto on the 2 blank lines

> + cmd = "apt-key adv --keyserver keyserver.ubuntu.com " \
> + "--recv-keys F7F9102D6A8DFC40"
> + try:
> + subprocess.check_call(cmd.split(' '))
> + except:
> + juju_log(MSG_ERROR, "Error importing repo key ")

That's a bit awkward to write a string and split. how about do this:

  def import_ci_ppa_keys():
     cmd = ['apt-key', 'adv', '--keyserver', 'keyserver.ubuntu.com',
            '--recv-keys', 'F7F9102D6A8DFC40']
     try:
         subprocess.check_call(cmd)
     except:
         juju_log(MSG_ERROR, "Error importing repo key ")

Also - what is "F7F9102D6A8DFC40"? Seems like this should probably come
from config.yaml?

You also might name the function "import_ppa_keys" so this isn't totally
tied to ci-airlines (I know it is totally tied to ci-airlines, but lets
not make the problem worse).

> @@ -510,7 +534,8 @@
> else:
> run('git clone %s %s' % (repos_url, vcs_clone_dir))
> elif vcs == 'bzr' or vcs == 'bazaar' or vcs == 'branch':
> - run('bzr branch %s %s' % (repos_url, vcs_clone_dir))
> + run('http_proxy=%s https_proxy=%s bzr branch %s %s'
> + % (proxy_url, proxy_url, repos_url, vcs_clone_dir))

not sure - is this safe when no http_proxy was defined?

414. By Para Siva

pep8 fixes on changes and getting gpg fingerprint from config

415. By Para Siva

Execute proxy commands only if proxy is defined

416. By Para Siva

pep8 fixes on changes and getting gpg fingerprint from config-pep8fix2

Revision history for this message
Para Siva (psivaa) wrote :

Thanks doanac for the comments. They all should be fixed now. Could you please verify?

One note on pep8 warnings is that hooks.py in this charm throws quite a lot of warnings about lines that haven't been changed as part of this MP. I haven't attempted to fix all of them but only the lines that changed due to time limitation.

Revision history for this message
Andy Doan (doanac) wrote :

tried out inline comments for this.

417. By Para Siva

Taking the mthood specific vars from env

Revision history for this message
Para Siva (psivaa) wrote :

r417 should fix the inline comments for r416

418. By Para Siva

proxy-url and ppa-gpg-key renaming to be consistent with restish and rabbitmq charms

Revision history for this message
Para Siva (psivaa) wrote :

Curious if I could get a nod for this to go in so that we don't lose this work. This part alone is functionally in working order, although there are other tweaks needed in some other components for mthood to be fully functional.
This is in a state where it can be picked up later if mthood needs development.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Let's park that now indeed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charms/precise/python-django/config.yaml'
--- charms/precise/python-django/config.yaml 2014-03-10 22:25:00 +0000
+++ charms/precise/python-django/config.yaml 2014-06-06 10:05:35 +0000
@@ -22,6 +22,14 @@
22 type: string22 type: string
23 default: ""23 default: ""
24 description: The vcs url to checkout.24 description: The vcs url to checkout.
25 proxy-url:
26 type: string
27 default: ""
28 description: The http proxy url for private clouds.
29 ppa-gpg-key:
30 type: string
31 default: ""
32 description: GPG key fingerprint for the PPA
25 repos_username:33 repos_username:
26 type: string34 type: string
27 default: ""35 default: ""
2836
=== modified file 'charms/precise/python-django/hooks/hooks.py'
--- charms/precise/python-django/hooks/hooks.py 2014-03-10 22:25:00 +0000
+++ charms/precise/python-django/hooks/hooks.py 2014-06-06 10:05:35 +0000
@@ -1,5 +1,4 @@
1#!/usr/bin/env python1#!/usr/bin/env python
2# vim: et ai ts=4 sw=4:
32
4import base643import base64
5import json4import json
@@ -10,12 +9,13 @@
10import subprocess9import subprocess
11import sys10import sys
12import time11import time
12import textwrap
13from pwd import getpwnam13from pwd import getpwnam
14from grp import getgrnam14from grp import getgrnam
15from random import choice15from random import choice
1616
17CHARM_PACKAGES = ["python-pip", "python-jinja2", "mercurial", "git-core",17CHARM_PACKAGES = ["python-pip", "python-jinja2", "mercurial", "git-core",
18 "subversion", "bzr", "gettext"]18 "subversion", "bzr", "gettext", "tsocks"]
1919
20INJECTED_WARNING = """20INJECTED_WARNING = """
21#------------------------------------------------------------------------------21#------------------------------------------------------------------------------
@@ -352,6 +352,7 @@
352 this_host = run("unit-get private-address")352 this_host = run("unit-get private-address")
353 return this_host.strip()353 return this_host.strip()
354354
355
355def process_template(template_name, template_vars, destination):356def process_template(template_name, template_vars, destination):
356 # --- exported service configuration file357 # --- exported service configuration file
357 from jinja2 import Environment, FileSystemLoader358 from jinja2 import Environment, FileSystemLoader
@@ -365,6 +366,16 @@
365 with open(destination, 'w') as inject_file:366 with open(destination, 'w') as inject_file:
366 inject_file.write(str(template))367 inject_file.write(str(template))
367368
369
370def import_ppa_keys():
371 cmd = ['apt-key', 'adv', '--keyserver', 'keyserver.ubuntu.com',
372 '--recv-keys', ppa_gpg_key]
373 try:
374 subprocess.check_call(cmd)
375 except:
376 juju_log(MSG_ERROR, "Error importing repo key")
377
378
368def configure_and_install(rel):379def configure_and_install(rel):
369380
370 def _import_key(id):381 def _import_key(id):
@@ -377,12 +388,16 @@
377388
378 if rel == 'distro':389 if rel == 'distro':
379 return apt_get_install("python-django")390 return apt_get_install("python-django")
391
380 elif rel[:4] == "ppa:":392 elif rel[:4] == "ppa:":
393 if ppa_gpg_key:
394 import_ppa_keys()
381 src = rel395 src = rel
382 subprocess.check_call(["add-apt-repository", "-y", src])396 subprocess.check_call(["add-apt-repository", "-y", src])
383 apt_get_update()397 apt_get_update()
384398
385 return apt_get_install("python-django")399 return apt_get_install("python-django")
400
386 elif rel[:3] == "deb":401 elif rel[:3] == "deb":
387 l = len(rel.split('|'))402 l = len(rel.split('|'))
388 if l == 2:403 if l == 2:
@@ -465,6 +480,17 @@
465 subprocess.check_call(cmd, shell=True)480 subprocess.check_call(cmd, shell=True)
466481
467482
483def setup_apt_proxy():
484 apt_conf= textwrap.dedent("""\
485 Acquire::http::proxy "%s";
486 Acquire::https::proxy "%s";
487 Acquire::HTTP::PROXY "%s";
488 Acquire::HTTPS::PROXY "%s";
489 """ % (proxy_url, proxy_url, proxy_url, proxy_url))
490 with open('/etc/apt/apt.conf.d/95proxies', 'w') as f:
491 f.write(apt_conf)
492
493
468###############################################################################494###############################################################################
469# Hook functions495# Hook functions
470###############################################################################496###############################################################################
@@ -475,6 +501,8 @@
475 time.sleep(10)501 time.sleep(10)
476 else:502 else:
477 break503 break
504 if proxy_url:
505 setup_apt_proxy()
478506
479 configure_and_install(django_version)507 configure_and_install(django_version)
480508
@@ -510,7 +538,11 @@
510 else:538 else:
511 run('git clone %s %s' % (repos_url, vcs_clone_dir))539 run('git clone %s %s' % (repos_url, vcs_clone_dir))
512 elif vcs == 'bzr' or vcs == 'bazaar' or vcs == 'branch':540 elif vcs == 'bzr' or vcs == 'bazaar' or vcs == 'branch':
513 run('bzr branch %s %s' % (repos_url, vcs_clone_dir))541 if proxy_url:
542 run('http_proxy=%s https_proxy=%s bzr branch %s %s'
543 % (proxy_url, proxy_url, repos_url, vcs_clone_dir))
544 else:
545 run('bzr branch %s %s' % (repos_url, vcs_clone_dir))
514 elif vcs == 'svn' or vcs == 'subversion':546 elif vcs == 'svn' or vcs == 'subversion':
515 run('svn co %s %s' % (repos_url, vcs_clone_dir))547 run('svn co %s %s' % (repos_url, vcs_clone_dir))
516 elif vcs == 'tarball':548 elif vcs == 'tarball':
@@ -810,6 +842,8 @@
810repos_username = config_data['repos_username']842repos_username = config_data['repos_username']
811repos_password = config_data['repos_password']843repos_password = config_data['repos_password']
812repos_branch = config_data['repos_branch']844repos_branch = config_data['repos_branch']
845proxy_url = config_data['proxy-url']
846ppa_gpg_key = config_data['ppa-gpg-key']
813847
814project_template_extension = config_data['project_template_extension']848project_template_extension = config_data['project_template_extension']
815project_template_url = config_data['project_template_url']849project_template_url = config_data['project_template_url']
816850
=== modified file 'juju-deployer/deploy.py'
--- juju-deployer/deploy.py 2014-05-07 01:25:30 +0000
+++ juju-deployer/deploy.py 2014-06-06 10:05:35 +0000
@@ -56,7 +56,7 @@
56 value))56 value))
5757
5858
59def check_environment():59def check_environment(args):
60 '''Cheetah requires environment variables for populating our templates'''60 '''Cheetah requires environment variables for populating our templates'''
61 cheetah_vars = {61 cheetah_vars = {
62 'OS_USERNAME': None,62 'OS_USERNAME': None,
@@ -77,6 +77,12 @@
77 'CI_MASTER_PPA': 'ppa:ci-engineering-airline/ci-archive',77 'CI_MASTER_PPA': 'ppa:ci-engineering-airline/ci-archive',
78 }78 }
79 missing_required = []79 missing_required = []
80 if args.mthood_deployment:
81 os.environ['CI_PPA'] = 'ppa:canonical-ci-engineering/mthood-phase-0'
82 if not os.environ.get('CI_PRIVATE_HTTP_PROXY'):
83 missing_required.append('CI_PRIVATE_HTTP_PROXY')
84 if not os.environ.get('CI_PPA_GPG_KEY'):
85 missing_required.append('CI_PPA_GPG_KEY')
80 for key in cheetah_vars:86 for key in cheetah_vars:
81 if key not in os.environ or len(os.environ[key]) == 0:87 if key not in os.environ or len(os.environ[key]) == 0:
82 default = cheetah_vars[key]88 default = cheetah_vars[key]
@@ -352,13 +358,16 @@
352 parser.add_argument('--private-launchpad', action='store_true',358 parser.add_argument('--private-launchpad', action='store_true',
353 help='''Sets the environment to use proper Launchpad359 help='''Sets the environment to use proper Launchpad
354 instance.''', default=False)360 instance.''', default=False)
361 parser.add_argument('--mthood-deployment', action='store_true',
362 help='''Sets the environment to use mthood specific
363 variables.''', default=False)
355 return parser.parse_args(args)364 return parser.parse_args(args)
356365
357366
358def main():367def main():
359 args = _get_args()368 args = _get_args()
360369
361 check_environment()370 check_environment(args)
362371
363 # You can configure the system to use private PPAs only or by providing372 # You can configure the system to use private PPAs only or by providing
364 # the option --private-ppas-only or by setting the environment variable373 # the option --private-ppas-only or by setting the environment variable
365374
=== modified file 'juju-deployer/ppa-assigner.yaml.tmpl'
--- juju-deployer/ppa-assigner.yaml.tmpl 2014-03-10 22:25:00 +0000
+++ juju-deployer/ppa-assigner.yaml.tmpl 2014-06-06 10:05:35 +0000
@@ -9,6 +9,8 @@
9 repos_url: ${CI_BRANCH}9 repos_url: ${CI_BRANCH}
10 additional_distro_packages: python-oauth, python-launchpadlib, python-yaml, python-tastypie, python-django-south10 additional_distro_packages: python-oauth, python-launchpadlib, python-yaml, python-tastypie, python-django-south
11 django_version: ${CI_PPA}11 django_version: ${CI_PPA}
12 proxy-url: ${CI_PRIVATE_HTTP_PROXY}
13 ppa-gpg-key: ${CI_PPA_GPG_KEY}
12 application_path: ppa-assigner/14 application_path: ppa-assigner/
13 django_settings: ppa_assigner.settings15 django_settings: ppa_assigner.settings
14 django_south: True16 django_south: True
1517
=== modified file 'juju-deployer/ticket-system.yaml.tmpl'
--- juju-deployer/ticket-system.yaml.tmpl 2014-02-25 14:14:43 +0000
+++ juju-deployer/ticket-system.yaml.tmpl 2014-06-06 10:05:35 +0000
@@ -18,6 +18,8 @@
18 repos_url: ${CI_BRANCH}18 repos_url: ${CI_BRANCH}
19 additional_distro_packages: python-lazr.enum, python-yaml, python-tastypie, python-django-south19 additional_distro_packages: python-lazr.enum, python-yaml, python-tastypie, python-django-south
20 django_version: ${CI_PPA}20 django_version: ${CI_PPA}
21 proxy-url: ${CI_PRIVATE_HTTP_PROXY}
22 ppa-gpg-key: ${CI_PPA_GPG_KEY}
21 unit-config: include-base64://configs/unit_config.yaml23 unit-config: include-base64://configs/unit_config.yaml
22 application_path: ticket_system/24 application_path: ticket_system/
23 django_settings: ticket_system.settings25 django_settings: ticket_system.settings

Subscribers

People subscribed via source and target branches