~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/devscripts/ec2test/instance.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-12-22 04:18:30 UTC
  • mfrom: (14564.3.2 megalint-6)
  • Revision ID: launchpad@pqm.canonical.com-20111222041830-444w19r626s6qkzj
[r=jtv][no-qa] Lint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    ]
10
10
 
11
11
import code
 
12
from datetime import datetime
12
13
import errno
13
14
import glob
14
15
import os
18
19
import sys
19
20
import time
20
21
import traceback
21
 
from datetime import datetime
 
22
 
22
23
from bzrlib.errors import BzrCommandError
23
24
from devscripts.ec2test.session import EC2SessionName
24
25
import paramiko
95
96
apt-key adv --recv-keys --keyserver pool.sks-keyservers.net ece2800bacf028b31ee3657cd702bf6b8c6c1efd # bzr
96
97
 
97
98
aptitude update
98
 
LANG=C aptitude -y install language-pack-en   # Do this first so later things don't complain about locales
 
99
 
 
100
# Do this first so later things don't complain about locales:
 
101
LANG=C aptitude -y install language-pack-en
 
102
 
99
103
aptitude -y full-upgrade
100
104
 
101
105
# This next part is cribbed from rocketfuel-setup
309
313
            self._ec2test_user_has_keys = False
310
314
        else:
311
315
            raise BzrCommandError(
312
 
                'failed to start: %s: %r\n' % (
313
 
                    self._boto_instance.state, self._boto_instance.state_reason))
 
316
                "failed to start: %s: %r\n" % (
 
317
                    self._boto_instance.state,
 
318
                    self._boto_instance.state_reason,
 
319
                    ))
314
320
 
315
321
    def shutdown(self):
316
322
        """Shut down the instance."""
343
349
            'look_for_keys': False,
344
350
            }
345
351
        for count in range(20):
 
352
            caught_errors = (
 
353
                socket.error,
 
354
                paramiko.AuthenticationException,
 
355
                EOFError,
 
356
                )
346
357
            try:
347
358
                ssh.connect(self.hostname, **connect_args)
348
 
            except (socket.error, paramiko.AuthenticationException, EOFError), e:
 
359
            except caught_errors as e:
349
360
                self.log('.')
350
 
                if getattr(e, 'errno', None) not in (
351
 
                        errno.ECONNREFUSED, errno.ETIMEDOUT, errno.EHOSTUNREACH):
 
361
                not_connected = [
 
362
                    errno.ECONNREFUSED,
 
363
                    errno.ETIMEDOUT,
 
364
                    errno.EHOSTUNREACH,
 
365
                    ]
 
366
                if getattr(e, 'errno', None) not in not_connected:
352
367
                    self.log('ssh _connect: %r\n' % (e,))
353
368
                if count < 9:
354
369
                    time.sleep(5)
532
547
        # The bucket `name` needs to exist and be accessible. We create it
533
548
        # here to reserve the name. If the bucket already exists and conforms
534
549
        # to the above requirements, this is a no-op.
535
 
        # 
 
550
        #
536
551
        # The API for region creation is a little quirky: you apparently can't
537
552
        # explicitly ask for 'us-east-1' you must just say '', etc.
538
553
        location = self._credentials.region_name