Merge lp:~nuclearbob/utah/bug1087679 into lp:utah

Proposed by Max Brustkern
Status: Merged
Approved by: Javier Collado
Approved revision: 781
Merged at revision: 778
Proposed branch: lp:~nuclearbob/utah/bug1087679
Merge into: lp:utah
Diff against target: 92 lines (+33/-5)
2 files modified
utah/config.py (+29/-5)
utah/provisioning/provisioning.py (+4/-0)
To merge this branch: bzr merge lp:~nuclearbob/utah/bug1087679
Reviewer Review Type Date Requested Status
Javier Collado (community) Approve
Max Brustkern (community) Needs Resubmitting
Review via email: mp+138811@code.launchpad.net

Description of the change

This branch changes SSHMixin to use config.user when connecting for file transfers. I found this error when I used a different user while working on lp:1087679 I think we may be able to fix that issue with just a preseed change, but I'm still testing that. I know we can fix it with a preseed change and this patch, and I think this patch is worth having anyway, since it fixes a potential problem with different configuration settings.

To post a comment you must log in.
lp:~nuclearbob/utah/bug1087679 updated
775. By Max Brustkern

Added support for rewriting ~-based paths in config options

776. By Max Brustkern

Properly quoted option names

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

I've added support to config for rewriting ~-based paths. The idea behind this is that we can specify ~/.ssh/utah as the sshprivatekey, and then we won't have to worry about what user is running the job. I'm testing this now.

review: Needs Information
lp:~nuclearbob/utah/bug1087679 updated
777. By Max Brustkern

Corrected global variable capitalization

778. By Max Brustkern

Added support for None types

779. By Max Brustkern

Fixed pep8 warning

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

I like the idea of expanding user path automatically.

Looking at the `config.py` I see that `os.path.expanduser` is still used for:
- sshprivatekey
- sshpublickey
- sshknonhosts
- vmpath

Please remove those calls since the user path is going to be expanded anyway
later.

review: Needs Fixing
lp:~nuclearbob/utah/bug1087679 updated
780. By Max Brustkern

Removed things that get expanded later from the list of things to expand the user path on

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

Those are out now.

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

What I meant is that it made sense to me to remove all the calls to
`os.path.expanduser` in the `LOCALDEFAULTS` dictionary to have just a common
place where `os.path.expanduser` was called.

However, what I see is those calls are still there and the keys affected have
been removed from `PATHOPTIONS`. This removes some duplication as well, but I'm
not sure why this is the best option. I guess it's probably based on the way
`LOCALDEFAULTS` is processed. Is that the case?

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

Okay, I think I understand better now. LOCALDEFAULTS contains all the keys that can't be written to the config file during package build time, because they depend on local system things (such as the expansion of user paths.) Would it make more sense to remove the expanduser from their definitions and put them back in PATHOPTIONS? That would make sense to me.

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

Yes, that's what I was trying to ask for in my first comment.

lp:~nuclearbob/utah/bug1087679 updated
781. By Max Brustkern

Moved expanduser around per Javier's suggestion

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

Okay, that should be better now.

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

Looks good to me now. Thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/config.py'
2--- utah/config.py 2012-12-10 13:01:20 +0000
3+++ utah/config.py 2012-12-10 19:02:18 +0000
4@@ -143,16 +143,15 @@
5 # Hostname (used for logfile among other things)
6 hostname=socket.gethostname(),
7 # SSH private key to use for provisioned machine logins
8- sshprivatekey=os.path.join(os.path.expanduser('~'), '.ssh', 'utah'),
9+ sshprivatekey=os.path.join('~', '.ssh', 'utah'),
10 # SSH public key to install on provisioned machines
11- sshpublickey=os.path.join(os.path.expanduser('~'), '.ssh', 'utah.pub'),
12+ sshpublickey=os.path.join('~', '.ssh', 'utah.pub'),
13 # SSH known hosts file
14- sshknownhosts=os.path.join(os.path.expanduser('~'), '.ssh',
15- 'known_hosts'),
16+ sshknownhosts=os.path.join('~', '.ssh', 'known_hosts'),
17 # User to install and use on provisioned machines
18 user=getpass.getuser(),
19 # Path for VM files
20- vmpath=os.path.join(os.path.expanduser('~'), 'vm'),
21+ vmpath=os.path.join('~', 'vm'),
22 )
23
24 # These depend on other config options, so they're added last.
25@@ -231,6 +230,31 @@
26 sys.stderr.write(conffile + ' is not a valid JSON file')
27
28
29+# Support ~-based paths on variables that use paths
30+PATHOPTIONS = (
31+ 'dlcommand',
32+ 'image',
33+ 'initrd',
34+ 'isodir',
35+ 'kernel',
36+ 'logpath',
37+ 'nfsconfigfile',
38+ 'preseed',
39+ 'pxedir',
40+ 'wwwdir',
41+ 'xml',
42+ 'sshprivatekey',
43+ 'sshpublickey',
44+ 'sshknownhosts',
45+ 'vmpath',
46+ 'logfile',
47+ 'debuglog',
48+)
49+for option in PATHOPTIONS:
50+ if CONFIG[option] is not None:
51+ CONFIG[option] = os.path.expanduser(CONFIG[option])
52+
53+
54 # Allow variables to be accessed via config.variable
55 locals().update(CONFIG)
56
57
58=== modified file 'utah/provisioning/provisioning.py'
59--- utah/provisioning/provisioning.py 2012-12-06 16:30:34 +0000
60+++ utah/provisioning/provisioning.py 2012-12-10 19:02:18 +0000
61@@ -742,6 +742,7 @@
62
63 self.activecheck()
64 self.ssh_client.connect(self.name,
65+ username=config.user,
66 key_filename=config.sshprivatekey)
67 sftp_client = self.ssh_client.open_sftp()
68 failed = []
69@@ -775,6 +776,7 @@
70
71 self.activecheck()
72 self.ssh_client.connect(self.name,
73+ username=config.user,
74 key_filename=config.sshprivatekey)
75 sftp_client = self.ssh_client.open_sftp()
76 if os.path.isdir(target):
77@@ -799,6 +801,7 @@
78 """
79 self.activecheck()
80 self.ssh_client.connect(self.name,
81+ username=config.user,
82 key_filename=config.sshprivatekey)
83 sftp_client = self.ssh_client.open_sftp()
84 myfiles = []
85@@ -871,6 +874,7 @@
86 self.logger.info('Checking for ssh availability')
87 try:
88 self.ssh_client.connect(self.name,
89+ username=config.user,
90 key_filename=config.sshprivatekey)
91 except socket.error as err:
92 raise UTAHProvisioningException(str(err), retry=True)

Subscribers

People subscribed via source and target branches