Merge lp:~nuclearbob/utah/internal-jsonschema into lp:utah

Proposed by Max Brustkern
Status: Merged
Merged at revision: 699
Proposed branch: lp:~nuclearbob/utah/internal-jsonschema
Merge into: lp:utah
Diff against target: 147 lines (+73/-22)
4 files modified
debian/control (+1/-1)
debian/utah.postinst (+12/-0)
debian/utah.prerm (+19/-0)
utah/provisioning/provisioning.py (+41/-21)
To merge this branch: bzr merge lp:~nuclearbob/utah/internal-jsonschema
Reviewer Review Type Date Requested Status
Javier Collado (community) Needs Fixing
Review via email: mp+121891@code.launchpad.net

Description of the change

To address https://bugs.launchpad.net/utah/+bug/1042895, this downloads a python-jsonschema deb from the stable PPA during postinstall, then installs that before installing the client deb.

To post a comment you must log in.
Revision history for this message
Javier Collado (javier.collado) wrote :

I don't really like much the idea of downloading the jsonschema package from the PPA when the server is installed. However, it's true that it makes things easier when the VM has connection problems. What happens when the machine where the server is installed has connection problems is something I haven't tested.

Anyway, I have some suggestions:

- Drop code to add the PPA to the client in the latecommand (isn't going to be used after all)

- Update "debian/control" for "utah-client" to have "python-jsonschema (> 0.2)". This will prevent the client from being installed when the expected package version isn't available.

- Replace `os.listdir`:

  for myfile in os.listdir(debpath):
      if (myfile.startswith('python-jsonschema_') and
          myfile.endswith('_all.deb')):
          debpath = os.path.join(debpath, myfile)
          break
  debpath = os.path.normpath(debpath)
  if not os.path.isfile(debpath):
      raise UTAHProvisioningException('python-jsonschema package file '
                                      'not found in {path}\n'
                                      .format(path=debpath))
  return debpath

with `glob.glob` :

  from glob import glob

  deb_file_glob = os.path.join(debpath, 'python-jsonschema_*_all.deb')
  deb_files = glob(deb_file_glob)
  if not deb_files:
      raise UTAHProvisioningException('python-jsonschema package file '
                                      'not found in {path}\n'
                                      .format(path=debpath))
  deb_file = deb_files[0]
  return deb_file

review: Needs Fixing
Revision history for this message
Max Brustkern (nuclearbob) wrote :

I think we've already determined we don't want to carry the jsonschema code in utah, so we have a few other options for how to get it:
- Add the PPA to the client system
  If we don't have internet access from the client, this will fail.
- Carry a jsonschema deb file in the utah tree
  This is probably a worse idea than carrying the source, so I don't think we should consider it unless we rule out all the other options.
- Download the jsonschema deb from the PPA during the package build.
  I don't know how to make this work on the buildd right now. I'm not sure if we can.
- Use a recipe that inserts a branch containing the jsonschema code into the utah build tree, and build a deb during package build time.
  If we have the jsconschema code in a branch in launchpad, this seems doable. I like this option the best, but there are probably drawbacks to it that I'm not thinking of.

Let me know what you think, or if you can think of other options I've left out, and we can figure something out.

Revision history for this message
Javier Collado (javier.collado) wrote :

@Max

According to this link:
https://help.launchpad.net/Packaging/PPA/BuildingASourcePackage#Dependencies
it should be possible to add a "Build-Depends" section against a "python-jsonschema" version found in a PPA.

After that, it should be possible to get the sources for "python-jsonschema", build it and include as part of the "utah" package itself. This way if the package build succeeds, then we now that the .deb for jsonschema will be available without any risk of a postinstall script failure.

What do you think about this? If you like the idea, I can create a new branch and give it a try.

Revision history for this message
Max Brustkern (nuclearbob) wrote :

I like this idea, but I'm not sure if the buildd's have access to PPAs. If you want to give it a try, go for it. If it works, it's definitely my favorite idea so far.

Revision history for this message
Javier Collado (javier.collado) wrote :

I've spent some time on some changes based on your branch to get the package from the PPA at build time instead of at installation time:
lp:~javier.collado/utah/bug1042895

In my machine, it worked fine and now I'm waiting for a build in my PPA to make sure that the build dependency can be retrieved correctly in the launchpad environment. If that succeeds, then I'll create a merge proposal.

Revision history for this message
Max Brustkern (nuclearbob) wrote :

I'll be interested to see how that goes. I've had success building locally with similar setups in the past, but I'm concerned about the process working on a buildd. I hope it does, and then we can finally get this checked off.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2012-08-14 16:55:16 +0000
3+++ debian/control 2012-08-29 15:51:18 +0000
4@@ -11,7 +11,7 @@
5 Package: utah
6 Architecture: all
7 Depends: ${misc:Depends}, ${python:Depends},
8- bzr, bsdtar, git, libvirt-bin, lzma,
9+ bzr, bsdtar, git, libvirt-bin, lzma, dpkg-dev,
10 python-apt, python-libvirt, python-jsonschema,
11 python-netifaces, python-paramiko, python-psutil, python-yaml,
12 utah-client (=${binary:Version})
13
14=== modified file 'debian/utah.postinst'
15--- debian/utah.postinst 2012-08-14 15:09:17 +0000
16+++ debian/utah.postinst 2012-08-29 15:51:18 +0000
17@@ -1,5 +1,15 @@
18 #!/bin/bash -e
19
20+function getjsonschema
21+{
22+ cd /usr/share/utah
23+ PPA="http://ppa.launchpad.net/utah/stable/ubuntu"
24+ ARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
25+ SERIES=$(lsb_release -sc)
26+ wget "$PPA/$(wget "$PPA/dists/$SERIES/main/binary-$ARCH/Packages" -O - 2>/dev/null | grep "python-jsonschema_.*_all.deb" | awk '{print $2}')"
27+ cd - > /dev/null
28+}
29+
30 function configure
31 {
32 if [ -f "/etc/utah/dns" ]
33@@ -92,6 +102,8 @@
34 usermod -a -G utah $USER
35 done
36 fi
37+
38+ getjsonschema
39 }
40
41 case $1 in
42
43=== added file 'debian/utah.prerm'
44--- debian/utah.prerm 1970-01-01 00:00:00 +0000
45+++ debian/utah.prerm 2012-08-29 15:51:18 +0000
46@@ -0,0 +1,19 @@
47+#!/bin/bash -e
48+
49+function cleanup
50+{
51+ rm -f /usr/share/utah/python-jsonschema_*_all.deb
52+}
53+
54+case "$1" in
55+ remove|purge|abort-install)
56+ cleanup
57+ ;;
58+ upgrade|failed-upgrade|abort-upgrade)
59+ ;;
60+ *)
61+ echo "$0: didn't understand being called with '$1'" 1>&2
62+ exit 0
63+ ;;
64+esac
65+#DEBHELPER#
66
67=== modified file 'utah/provisioning/provisioning.py'
68--- utah/provisioning/provisioning.py 2012-08-24 18:26:16 +0000
69+++ utah/provisioning/provisioning.py 2012-08-29 15:51:18 +0000
70@@ -255,6 +255,25 @@
71 self.logger.debug('Client deb path is ' + debpath)
72 return debpath
73
74+ def getjsonschemadeb(self):
75+ """
76+ Return the path of the .deb file for the python-jsonschema installed
77+ as part of the main package.
78+ """
79+ debpath = os.path.join('/usr', 'share', 'utah')
80+ for myfile in os.listdir(debpath):
81+ if (myfile.startswith('python-jsonschema_') and
82+ myfile.endswith('_all.deb')):
83+ debpath = os.path.join(debpath, myfile)
84+ break
85+ debpath = os.path.normpath(debpath)
86+ if not os.path.isfile(debpath):
87+ raise UTAHProvisioningException('python-jsonschema package file '
88+ 'not found in {path}\n'
89+ .format(path=debpath))
90+ self.logger.debug('python-jsconschema deb path is ' + debpath)
91+ return debpath
92+
93 def installclient(self):
94 """
95 Install the utah-client package on the
96@@ -262,29 +281,30 @@
97 """
98 self.logger.info('Installing client deb on machine')
99 tmppath = os.path.normpath('/tmp')
100- clientdeb = self.getclientdeb()
101- try:
102- self.uploadfiles([clientdeb], tmppath)
103- except UTAHProvisioningException as err:
104+ debs = [self.getjsonschemadeb(), self.getclientdeb()]
105+ for deb in debs:
106 try:
107- for myfile in err.files:
108- if 'utah-client' in myfile:
109- raise UTAHProvisioningException('Client file not '
110- + 'found; UTAH was probably updated '
111- + 'during the run. Please try again.',
112- retry=True)
113- raise err
114- except AttributeError:
115- raise err
116+ self.uploadfiles([deb], tmppath)
117+ except UTAHProvisioningException as err:
118+ try:
119+ for myfile in err.files:
120+ if deb in myfile:
121+ raise UTAHProvisioningException('File not '
122+ 'found: ' + deb + '; UTAH was probably '
123+ 'updated during the run. '
124+ 'Please try again.', retry=True)
125+ raise err
126+ except AttributeError:
127+ raise err
128
129- remote_clientdeb = os.path.join(tmppath, os.path.basename(clientdeb))
130- install_command = ('DEBIAN_FRONTEND=noninteractive '
131- 'gdebi -n -q {}'
132- .format(remote_clientdeb))
133- returncode, stdout, stderr = self.run(install_command, root=True)
134- if (returncode != 0
135- or re.search(r'script returned error exit status \d+', stderr)):
136- raise UTAHProvisioningException('Failed to install client\n')
137+ remote_deb = os.path.join(tmppath, os.path.basename(deb))
138+ install_command = ('DEBIAN_FRONTEND=noninteractive '
139+ 'gdebi -n -q {}'
140+ .format(remote_deb))
141+ returncode, stdout, stderr = self.run(install_command, root=True)
142+ if (returncode != 0
143+ or re.search(r'script returned error exit status \d+', stderr)):
144+ raise UTAHProvisioningException('Failed to install client\n')
145
146 def _provision(self):
147 """

Subscribers

People subscribed via source and target branches