Merge ~hloeung/ubuntu-repository-cache:fixes into ubuntu-repository-cache:master

Proposed by Haw Loeung
Status: Merged
Approved by: Haw Loeung
Approved revision: 0a14d5aa5bd7921d8244037a8000cb850dc88dae
Merged at revision: 2d80ed1f021242d64ba05dec2cf43d751e437898
Proposed branch: ~hloeung/ubuntu-repository-cache:fixes
Merge into: ubuntu-repository-cache:master
Diff against target: 190 lines (+1/-164)
2 files modified
Makefile (+1/-6)
dev/null (+0/-158)
Reviewer Review Type Date Requested Status
Paul Collins lgtm Approve
Canonical IS Reviewers Pending
Review via email: mp+429342@code.launchpad.net

Commit message

bzr to git conversion clean up

To post a comment you must log in.
Revision history for this message
Paul Collins (pjdc) :
review: Approve (lgtm)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Merge proposal is approved, but source revision has changed, setting status to needs review.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 2d80ed1f021242d64ba05dec2cf43d751e437898

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.bzrignore b/.gitignore
2similarity index 100%
3rename from .bzrignore
4rename to .gitignore
5diff --git a/Makefile b/Makefile
6index db53b16..3221da9 100644
7--- a/Makefile
8+++ b/Makefile
9@@ -46,11 +46,6 @@ lint:
10
11 clean:
12 @echo "Cleaning files"
13- @rm -rf build
14- @rm -rf htmlcov
15- @rm -rf .venv
16- @rm -rf .tox
17- @rm -rf ./tests/unit/__pycache__ ./reactive/__pycache__ ./lib/ubuntu_repository_cache/__pycache__ ./lib/ubuntu_repository_cache/tests/__pycache__ ./files/__pycache__
18- @rm -rf ./.coverage ./.juju-persistent-config ./.unit-state.db
19+ @git clean -ffXd
20
21 .PHONY: proof test lint
22diff --git a/lib/ubuntu-repository-cache/__init__.py b/lib/ubuntu-repository-cache/__init__.py
23deleted file mode 100644
24index e69de29..0000000
25--- a/lib/ubuntu-repository-cache/__init__.py
26+++ /dev/null
27diff --git a/lib/ubuntu-repository-cache/util.py b/lib/ubuntu-repository-cache/util.py
28deleted file mode 100644
29index 97f797d..0000000
30--- a/lib/ubuntu-repository-cache/util.py
31+++ /dev/null
32@@ -1,158 +0,0 @@
33-import aptsources.sourceslist
34-import functools
35-import glob
36-import os
37-import pwd
38-import random
39-import subprocess
40-import sys
41-
42-sys.path.insert(0, os.path.join(os.environ['CHARM_DIR'], 'lib'))
43-
44-from charmhelpers.core import ( # pylint: disable=F0401
45- hookenv,
46- host,
47- templating,
48-)
49-
50-LOG = hookenv.log
51-SERVICE = 'ubuntu-repository-cache'
52-
53-
54-def become_user(uname):
55- '''Change the effective uid/gid to that of the user specified by uname'''
56-
57- # Change effective uid/gid back to value from saved uid/gid
58- os.seteuid(os.getresuid()[2])
59- os.setegid(os.getresgid()[2])
60-
61- # Change to the requested user's uid/gid
62- pw_record = pwd.getpwnam(uname)
63- os.setegid(pw_record.pw_gid)
64- os.seteuid(pw_record.pw_uid)
65-
66-
67-# TODO Submit MP to include this in charmhelpers.core.host
68-def run_as_user(user_name):
69- '''A decorator to run a function as a particular user.
70-
71- This works as long as the saved uid (see os.getresuid()[2])
72- has permission to change the effective to that of the
73- desired uid/gid of the provided user name.
74- '''
75- def decorator(function):
76- def restore_saved_id():
77- os.seteuid(os.getresuid()[2])
78- os.setegid(os.getresgid()[2])
79-
80- def become_user(uname):
81- '''Change the effective uid/gid to the specified user
82- '''
83-
84- restore_saved_id()
85- pw_record = pwd.getpwnam(uname)
86- os.setegid(pw_record.pw_gid)
87- os.seteuid(pw_record.pw_uid)
88-
89- @functools.wraps(function)
90- def wrapper(*args, **kwargs):
91- # Remember the current effective uid/gid
92- orig_id = os.geteuid(), os.getegid()
93-
94- # Change to saved uid/gid so that wrapped functions can nest
95- # This assumes that the saved id has
96- restore_saved_id()
97-
98- # Set effective uid/gid for speficied user
99- pw_record = pwd.getpwnam(user_name)
100- os.setegid(pw_record.pw_gid)
101- os.seteuid(pw_record.pw_uid)
102-
103- result = function(*args, **kwargs)
104-
105- # Restore effective uid/gid
106- restore_saved_id()
107- os.seteuid(orig_id[0])
108- os.setegid(orig_id[1])
109-
110- return result
111- return wrapper
112- return decorator
113-
114-
115-def change_aptsources_url(url='http://archive.ubuntu.com/ubuntu'):
116- '''Change the URL for the current /etc/apt/sources.list
117-
118- This affects the URL for all sources in /etc/apt/sources.list
119- so care must be taken if the charm has added any custom source
120- URLs as it will alter them as well.
121-
122- Sources added with charmhelpers.fetch.add_source() are not affected
123- as those are added under /etc/apt/sources.list.d/.
124- '''
125-
126- sourceslist = aptsources.sourceslist.SourcesList()
127- sourceslist.refresh()
128- if not glob.glob('/etc/apt/sources.list.%s' % SERVICE):
129- sourceslist.backup(backup_ext=SERVICE)
130- distro = aptsources.distro.get_distro()
131- distro.get_sources(sourceslist)
132- distro.change_server(url)
133- sourceslist.save()
134-
135-
136-def render_configs():
137- '''Render the configuration templates for all required services'''
138-
139- LOG('Rendering configuration templates')
140- # Configure apache2
141- config = hookenv.config()
142- apache_context = {}
143- apache_context['DocumentRoot'] = '/srv/archive.ubuntu.com/'
144- apache_context['Sync_Host'] = config['sync-host']
145- templating.render('apache2/archive_ubuntu_com.conf',
146- '/etc/apache2/sites-available/archive_ubuntu_com.conf',
147- apache_context)
148- subprocess.check_call(['a2ensite', 'archive_ubuntu_com'])
149-
150- # Configure squid-deb-proxy
151- squid_context = {}
152- squid_context['Cache_Dir'] = '/var/cache/squid-deb-proxy'
153- squid_context['Cache_Size'] = config['cache-size']
154- squid_context['Cache_Mem'] = config['cache-mem']
155- squid_context['Max_Obj_Size'] = '512'
156- squid_context['Max_Obj_Size_Mem'] = '30'
157- templating.render('squid-deb-proxy/squid-deb-proxy.conf',
158- '/etc/squid-deb-proxy/squid-deb-proxy.conf',
159- squid_context)
160-
161- templating.render('squid-deb-proxy/allowed-networks-src.conf',
162- '/etc/squid-deb-proxy/allowed-networks-src.conf',
163- {})
164-
165- cron_context = {}
166- if not getattr(config, 'rsync-minutes', None):
167- config['rsync-minutes'] = random.randint(0, 59)
168- config.save()
169- cron_context['Minutes'] = config['rsync-minutes']
170- templating.render('cron/ubuntu-repository-cache_rsync.cron',
171- '/etc/cron.d/ubuntu-repository-cache_rsync',
172- cron_context)
173-
174-
175-def restart_services():
176- '''Reload/Restart all of the required services'''
177-
178- LOG('(Re)Starting required services')
179- if not os.access('/srv/archive.ubuntu.com/www/ubuntu', os.R_OK):
180- LOG('Mirrored metadata unavailble, not starting services')
181- host.service_stop('squid-deb-proxy')
182- host.service_stop('apache2')
183- return
184-
185- # TODO check that /srv/archive.ubuntu.com/www/ubuntu exists
186- # Start the services
187- host.service_reload('squid-deb-proxy', restart_on_failure=True)
188- # TODO check that http://localhost/ubuntu/pool/ responds
189- host.service_reload('apache2', restart_on_failure=True)
190- # TODO check that http://localhost/ubuntu/ responds

Subscribers

People subscribed via source and target branches