Merge lp:~salgado/offspring/path-independence into lp:offspring

Proposed by Guilherme Salgado
Status: Merged
Merged at revision: 89
Proposed branch: lp:~salgado/offspring/path-independence
Merge into: lp:offspring
Prerequisite: lp:~salgado/offspring/all-python-config
Diff against target: 189 lines (+40/-33)
7 files modified
config/offspring.cfg (+11/-3)
lib/offspring/__init__.py (+5/-0)
lib/offspring/build/bin/offspring-build (+7/-11)
lib/offspring/build/scripts/archive-builds (+7/-11)
lib/offspring/config.py (+8/-4)
lib/offspring/web/queuemanager/models.py (+2/-1)
lib/offspring/web/settings_production.py (+0/-3)
To merge this branch: bzr merge lp:~salgado/offspring/path-independence
Reviewer Review Type Date Requested Status
Cody A.W. Somerville Disapprove
Review via email: mp+76480@code.launchpad.net

This proposal supersedes a proposal from 2011-09-20.

Description of the change

This is a second attempt at trying to get these changes merged; they simplify things a lot for developers.

Here's what Michael said in the original merge proposal:

This finally is an I think ready branch to allow offspring to be easily run from places other than /srv.

The code to find offspring-builder-config is a touch horrible, but it won't be needed in the slave.

To post a comment you must log in.
Revision history for this message
Cody A.W. Somerville (cody-somerville) wrote :

Branch needs to be updated to use final solution accepted as part of all-python-config branch MPs,

review: Needs Fixing
Revision history for this message
Guilherme Salgado (salgado) wrote :

Ok, I've updated it.

Revision history for this message
Cody A.W. Somerville (cody-somerville) wrote :
Download full text (3.1 KiB)

First off, kudos to both you and Michael for working on this. Making it easier to run Offspring from locations other than /srv/ is valuable for a number of reasons including making it easier for developers to jump in and contribute (e.g. you've specifically mentioned making it easier to run tests for a branch as a motivation for pushing this change). I apologize for how long it has taken to get feedback on this branch. The problem is unfortunately not really an easy one to solve elegantly. I've very much wanted to find a way that I could accept the solution you've came up with but I've ultimately came to the conclusion that it is insufficient.

The one benefit the current rigidity provides is the deterministic nature in which Offspring will search for its configuration files independently of how we have Offspring installed. The tact this MP takes is to start making assumptions about how Offspring is installed and the relativity of assets, a coupling we currently do not have. This is at the very least a pragmatic approach to the problem since it is highly unlikely that anyone is installing Offspring in any other way sufficiently unique to cause a problem but it also doesn't seem like we're far off from wanting to support such scenarios (e.g. Debian packaging). Whereas currently such a scenario is reasonably possible, this change introduces assumptions that are directly incompatible to that objective. Additionally, the assumptions made in the bash scripts create a dependency on the location of the scripts within the codebase itself - it would not be immediately obvious that both offspring-build and archive-builds would now depend on being five directories beneath the assumed base directory (see 'for i in 1 2 3 4 5' loops). Thus it is almost ironic, and I say this only in good jest, that this branch is called 'path-independence'. ;)

The ability to set an environmental variable to override the location of the Offspring configuration file is entirely removed in this branch which I think has been a relatively easy to use (though not entirely effective in all scenarios, at least without some of the other changes you make in this branch) solution to this problem though not as 'automatic'. Most *nix programs and scripts look for their assets in a few different locations with each location checked before the next having a higher precedence to be used. It is also very common for an argument to be available to set the location of assets or configuration file(s). And lastly, it is also very common for applications to be customized/modified at build and/or install time to look in the locations desired by the operator. In Offspring itself, setuptools creates stub scripts that are basically hard coded to execute the real code since setuptools is privy to the absolute location of where it installs our python modules. I think we need to look for a solution that leverages some of these techniques to make it easier to run Offspring both from a branch as is desired but in a fashion that is not incompatible with Offspring being installed in a more traditional (and subsequently Debian policy compliant) fashion.

I'll be happy to discuss this with you further once...

Read more...

review: Disapprove
Revision history for this message
David Murphy (schwuk) wrote :

The review of this branch is ongoing.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config/offspring.cfg'
2--- config/offspring.cfg 2011-11-11 01:41:58 +0000
3+++ config/offspring.cfg 2011-11-18 14:41:20 +0000
4@@ -7,7 +7,15 @@
5 #===============================================================================
6 # Offspring Global Defaults
7 #
8+# Some options in this section are given defaults by code so that they
9+# can be referenced in subsitutions:
10+#
11 # base_dir: Base directory of offspring install
12+# hostname: The hostname of the running machine
13+# username: The name of the user running offspring
14+#
15+# The other options below are set normally:
16+#
17 # bin_dir: Directory to offspring binaries
18 # config_dir: Directory to offspring configuration files
19 # admin_email: E-mail admin notifications should be sent to by default
20@@ -21,7 +29,6 @@
21 #===============================================================================
22
23 [DEFAULT]
24-base_dir: /srv
25 bin_dir: %(base_dir)s/bin
26 config_dir: %(base_dir)s/config
27 log_dir: %(base_dir)s/logs
28@@ -140,6 +147,7 @@
29 poll_frequency: 20
30 logfile: %(log_dir)s/offspring-master.log
31 launchpad_oauth: %(config_dir)s/launchpad.oauth
32+result_directory: %(base_dir)s/builds
33
34 #===============================================================================
35 # Offspring publisher
36@@ -159,8 +167,8 @@
37
38 [publisher]
39 db: postgres://offspring:temp1234@localhost/offspring
40-development_pool: /srv/builds/
41-production_pool: /srv/partners/
42+development_pool: %(base_dir)s/builds/
43+production_pool: %(base_dir)s/partners/
44 signer_directory:
45 signer_files:
46 signer_results:
47
48=== modified file 'lib/offspring/__init__.py'
49--- lib/offspring/__init__.py 2010-11-29 08:27:24 +0000
50+++ lib/offspring/__init__.py 2011-11-18 14:41:20 +0000
51@@ -1,4 +1,9 @@
52 # Copyright 2010 Canonical Ltd. This software is licensed under the
53 # GNU Affero General Public License version 3 (see the file LICENSE).
54
55+import os
56+
57 __version__ = '0.0.1'
58+
59+offspring_root = os.path.abspath(
60+ os.path.join(os.path.dirname(__file__), '..', '..'))
61
62=== modified file 'lib/offspring/build/bin/offspring-build'
63--- lib/offspring/build/bin/offspring-build 2011-11-11 01:25:27 +0000
64+++ lib/offspring/build/bin/offspring-build 2011-11-18 14:41:20 +0000
65@@ -6,17 +6,13 @@
66 set -e
67
68 _Initialize() {
69- if [ -z "${OFFSPRING_CONFIGSCRIPT}" ]
70- then
71- OFFSPRING_CONFIGSCRIPT="/srv/scripts/offspring-builder-config"
72- fi
73-
74- if [ ! -x "${OFFSPRING_CONFIGSCRIPT}" ]
75- then
76- printf "Could not find config script at ${OFFSPRING_CONFIGSCRIPT}\n" >& 2
77- exit 1
78- fi
79-
80+ SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
81+ OFFSPRING_ROOT=$SCRIPT_PATH
82+ for i in 1 2 3 4 5;
83+ do
84+ OFFSPRING_ROOT="$(dirname "${OFFSPRING_ROOT}")"
85+ done
86+ OFFSPRING_CONFIGSCRIPT=${OFFSPRING_ROOT}/scripts/offspring-builder-config
87 eval $("${OFFSPRING_CONFIGSCRIPT}")
88
89 if [ "$?" -ne "0" ]
90
91=== modified file 'lib/offspring/build/scripts/archive-builds'
92--- lib/offspring/build/scripts/archive-builds 2011-11-11 01:25:27 +0000
93+++ lib/offspring/build/scripts/archive-builds 2011-11-18 14:41:20 +0000
94@@ -8,17 +8,13 @@
95 # XXX: This script needs to be rewritten to use new framework.
96 #
97
98-if [ -z "${OFFSPRING_CONFIGSCRIPT}" ]
99-then
100- OFFSPRING_CONFIGSCRIPT="/srv/scripts/offspring-builder-config"
101-fi
102-
103-if [ ! -x "${OFFSPRING_CONFIGSCRIPT}" ]
104-then
105- printf "Could not find config script at ${OFFSPRING_CONFIGSCRIPT}\n" >& 2
106- exit 1
107-fi
108-
109+SCRIPT_PATH="$(readlink -e "${0}" || which "${0}")"
110+OFFSPRING_ROOT=$SCRIPT_PATH
111+for i in 1 2 3 4 5;
112+do
113+ OFFSPRING_ROOT="$(dirname "${OFFSPRING_ROOT}")"
114+done
115+OFFSPRING_CONFIGSCRIPT="${OFFSPRING_ROOT}/scripts/offspring-builder-config"
116 eval $("${OFFSPRING_CONFIGSCRIPT}")
117
118 if [ "$?" -ne "0" ]
119
120=== modified file 'lib/offspring/config.py'
121--- lib/offspring/config.py 2011-11-11 01:13:02 +0000
122+++ lib/offspring/config.py 2011-11-18 14:41:20 +0000
123@@ -8,16 +8,23 @@
124 import os
125 import sys
126
127+from offspring import offspring_root
128+
129 config = None
130
131 def _read_config():
132 global config
133 config = SafeConfigParser()
134+ hostname = os.popen('hostname').read().strip()
135+ config.set('DEFAULT', 'base_dir', offspring_root)
136+ config.set('DEFAULT', 'hostname', hostname)
137+ config.set('DEFAULT', 'username', os.environ['USERNAME'])
138
139 if os.environ.has_key("OFFSPRING_CONFIGFILE"):
140 CONFIGFILE_PATH = os.environ["OFFSPRING_CONFIGFILE"]
141 else:
142- CONFIGFILE_PATH = "/srv/config/offspring.cfg"
143+ CONFIGFILE_PATH = os.path.join(
144+ offspring_root, 'config', 'offspring.cfg')
145 configFile = None
146 try:
147 configFile = open(CONFIGFILE_PATH)
148@@ -27,9 +34,6 @@
149 % (CONFIGFILE_PATH, e) )
150 sys.exit(1)
151 else:
152- hostname = os.popen('hostname').read().strip()
153- config.set('DEFAULT', 'hostname', hostname)
154- config.set('DEFAULT', 'username', os.environ['USERNAME'])
155 config.read([CONFIGFILE_PATH + '.' + hostname])
156 finally:
157 if configFile is not None:
158
159=== modified file 'lib/offspring/web/queuemanager/models.py'
160--- lib/offspring/web/queuemanager/models.py 2011-09-27 18:42:21 +0000
161+++ lib/offspring/web/queuemanager/models.py 2011-11-18 14:41:20 +0000
162@@ -19,6 +19,7 @@
163 models
164 )
165
166+from offspring import config
167 from offspring.enums import ProjectBuildStates
168
169
170@@ -303,7 +304,7 @@
171 def result_directory(self):
172 if self.name:
173 try:
174- base_dir = getattr(settings, 'BUILDRESULTS_DIRECTORY', '/srv/builds/')
175+ base_dir = config.master('result_directory')
176 buildDate, buildId = self.name.rsplit('-', 1)
177 except:
178 return None
179
180=== modified file 'lib/offspring/web/settings_production.py'
181--- lib/offspring/web/settings_production.py 2010-11-29 08:27:24 +0000
182+++ lib/offspring/web/settings_production.py 2011-11-18 14:41:20 +0000
183@@ -16,6 +16,3 @@
184 EMAIL_HOST = 'localhost'
185
186 MEDIA_URL = 'https://offspring.com/assets/'
187-
188-# Path to build results
189-BUILDRESULTS_DIRECTORY = '/srv/offspring.com/www/builds/'

Subscribers

People subscribed via source and target branches