~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: 2012-01-06 20:21:38 UTC
  • mfrom: (14646.2.1 bug912794)
  • Revision ID: launchpad@pqm.canonical.com-20120106202138-mnl55qu4h9iovgk4
[r=gary][bug=912794] update to newer launchpadlib

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