예제 #1
0
  def setUp(self):
    # mock out logging, since it clutters out test output
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()

    # next, pretend our ec2 credentials are properly set
    for credential in EC2Agent.REQUIRED_CREDENTIALS:
      os.environ[credential] = "baz"

    # finally, pretend that our ec2 image to use exists
    fake_ec2 = flexmock(name="fake_ec2")
    fake_ec2.should_receive('get_image').with_args('ami-ABCDEFG') \
      .and_return()
    flexmock(boto)
    boto.should_receive('connect_ec2').with_args('baz', 'baz').and_return(fake_ec2)

    # add in some instance variables so that we don't have
    # a lot IP addresses everywhere
    self.blank_input_yaml = None
    self.default_options = {
      'table' : 'cassandra'
    }
    self.ip_1 = '192.168.1.1'
    self.ip_2 = '192.168.1.2'
    self.ip_3 = '192.168.1.3'
    self.ip_4 = '192.168.1.4'
    self.ip_5 = '192.168.1.5'
    self.ip_6 = '192.168.1.6'
    self.ip_7 = '192.168.1.7'
    self.ip_8 = '192.168.1.8'
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.function = "appscale-add-keypair"

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()

    flexmock(tempfile)
    tempfile.should_receive('TemporaryFile').and_return(self.fake_temp_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='success', returncode=1)
    self.failed.should_receive('wait').and_return(1)
예제 #3
0
    def setUp(self):
        # mock out logging, since it clutters out test output
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('log').and_return()

        # next, pretend our ec2 credentials are properly set
        for credential in EC2Agent.REQUIRED_CREDENTIALS:
            os.environ[credential] = "baz"

        # finally, pretend that our ec2 image to use exists
        fake_ec2 = flexmock(name="fake_ec2")
        fake_ec2.should_receive('get_image').with_args('ami-ABCDEFG') \
          .and_return()
        flexmock(boto)
        boto.should_receive('connect_ec2').with_args(
            'baz', 'baz').and_return(fake_ec2)

        # add in some instance variables so that we don't have
        # a lot IP addresses everywhere
        self.blank_input_yaml = None
        self.default_options = {'table': 'cassandra'}
        self.ip_1 = '192.168.1.1'
        self.ip_2 = '192.168.1.2'
        self.ip_3 = '192.168.1.3'
        self.ip_4 = '192.168.1.4'
        self.ip_5 = '192.168.1.5'
        self.ip_6 = '192.168.1.6'
        self.ip_7 = '192.168.1.7'
        self.ip_8 = '192.168.1.8'
예제 #4
0
  def setUp(self):
    self.cloud_argv = ['--min', '1', '--max', '1', '--group', 'blargscale',
      '--infrastructure', 'ec2', '--machine', 'ami-ABCDEFG']
    self.cluster_argv = ['--ips', 'ips.yaml']
    self.function = "appscale-run-instances"

    # mock out all logging, since it clutters our output
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()

    # set up phony AWS credentials for each test
    # ones that test not having them present can
    # remove them
    for credential in EucalyptusAgent.REQUIRED_EC2_CREDENTIALS:
      os.environ[credential] = "baz"
    os.environ['EC2_URL'] = "http://boo"

    # similarly, pretend that our image does exist in EC2
    # and Euca
    fake_ec2 = flexmock(name="fake_ec2")
    fake_ec2.should_receive('get_image').with_args('ami-ABCDEFG') \
      .and_return()
    fake_ec2.should_receive('get_image').with_args('emi-ABCDEFG') \
      .and_return('anything')

    flexmock(boto)
    boto.should_receive('connect_ec2').with_args('baz', 'baz') \
      .and_return(fake_ec2)
    boto.should_receive('connect_euca').and_return(fake_ec2)
    def setUp(self):
        self.keyname = "boobazblargfoo"
        self.function = "appscale-terminate-instances"

        # mock out any writing to stdout
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive("log").and_return()
        AppScaleLogger.should_receive("verbose").and_return()

        # mock out all sleeping
        flexmock(time)
        time.should_receive("sleep").and_return()

        local_state = flexmock(LocalState)
        local_state.should_receive("shell").and_return("")

        # throw some default mocks together for when invoking via shell succeeds
        # and when it fails
        self.fake_temp_file = flexmock(name="fake_temp_file")
        self.fake_temp_file.should_receive("read").and_return("boo out")
        self.fake_temp_file.should_receive("close").and_return()
        self.fake_temp_file.should_receive("seek").with_args(0).and_return()

        flexmock(tempfile)
        tempfile.should_receive("NamedTemporaryFile").and_return(self.fake_temp_file)

        self.success = flexmock(name="success", returncode=0)
        self.success.should_receive("wait").and_return(0)

        self.failed = flexmock(name="failed", returncode=1)
        self.failed.should_receive("wait").and_return(1)

        # throw in some mocks that assume our EC2 environment variables are set
        for credential in EC2Agent.REQUIRED_EC2_CREDENTIALS:
            os.environ[credential] = "baz"
    def setUp(self):
        self.keyname = "boobazblargfoo"
        self.function = "appscale-gather-logs"

        # mock out any writing to stdout
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('log').and_return()

        # mock out all sleeping
        flexmock(time)
        time.should_receive('sleep').and_return()

        # throw some default mocks together for when invoking via shell succeeds
        # and when it fails
        self.fake_temp_file = flexmock(name='fake_temp_file')
        self.fake_temp_file.should_receive('read').and_return('boo out')
        self.fake_temp_file.should_receive('close').and_return()
        self.fake_temp_file.should_receive('seek').with_args(0).and_return()

        flexmock(tempfile)
        tempfile.should_receive('NamedTemporaryFile').and_return(
            self.fake_temp_file)

        self.success = flexmock(name='success', returncode=0)
        self.success.should_receive('wait').and_return(0)

        self.failed = flexmock(name='success', returncode=1)
        self.failed.should_receive('wait').and_return(1)
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.function = "appscale-upload-app"
    self.app_dir = "/tmp/baz/gbaz"

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()
    AppScaleLogger.should_receive('success').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()

    local_state = flexmock(LocalState)
    local_state.should_receive('shell').and_return()

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()
    self.fake_temp_file.should_receive('seek').with_args(0).and_return()

    flexmock(tempfile)
    tempfile.should_receive('NamedTemporaryFile').and_return(self.fake_temp_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='success', returncode=1)
    self.failed.should_receive('wait').and_return(1)
예제 #8
0
    def setUp(self):
        self.cloud_argv = [
            '--min', '1', '--max', '1', '--group', 'blargscale',
            '--infrastructure', 'ec2', '--machine', 'ami-ABCDEFG'
        ]
        self.cluster_argv = ['--ips', 'ips.yaml']
        self.function = "appscale-run-instances"

        # mock out all logging, since it clutters our output
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('log').and_return()

        # set up phony AWS credentials for each test
        # ones that test not having them present can
        # remove them
        for credential in EucalyptusAgent.REQUIRED_EC2_CREDENTIALS:
            os.environ[credential] = "baz"
        os.environ['EC2_URL'] = "http://boo"

        # similarly, pretend that our image does exist in EC2
        # and Euca
        fake_ec2 = flexmock(name="fake_ec2")
        fake_ec2.should_receive('get_image').with_args('ami-ABCDEFG') \
          .and_return()
        fake_ec2.should_receive('get_image').with_args('emi-ABCDEFG') \
          .and_return('anything')

        fake_price = flexmock(name='fake_price', price=1.00)
        fake_ec2.should_receive('get_spot_price_history').and_return(
            [fake_price])

        flexmock(boto)
        boto.should_receive('connect_ec2').with_args('baz', 'baz') \
          .and_return(fake_ec2)
        boto.should_receive('connect_euca').and_return(fake_ec2)
예제 #9
0
  def setUp(self):
    self.cloud_argv = ['--min', '1', '--max', '1', '--group', 'blargscale',
      '--infrastructure', 'ec2', '--machine', 'ami-ABCDEFG', '--zone',
      'my-zone-1b']
    self.cluster_argv = ['--ips', 'ips.yaml']
    self.function = "appscale-run-instances"

    # mock out all logging, since it clutters our output
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()

    # set up phony AWS credentials for each test
    # ones that test not having them present can
    # remove them
    for credential in EucalyptusAgent.REQUIRED_EC2_CREDENTIALS:
      os.environ[credential] = "baz"
    os.environ['EC2_URL'] = "http://boo"

    # pretend that our credentials are valid.
    fake_ec2 = flexmock(name="fake_ec2")
    fake_ec2.should_receive('get_all_instances')

    # similarly, pretend that our image does exist in EC2
    # and Euca
    fake_ec2.should_receive('get_image').with_args('ami-ABCDEFG') \
      .and_return()
    fake_ec2.should_receive('get_image').with_args('emi-ABCDEFG') \
      .and_return('anything')

    # Slip in mocks that assume our EBS volume exists in EC2.
    fake_ec2.should_receive('get_all_volumes').with_args(['vol-ABCDEFG']) \
      .and_return('anything')

    # Also pretend that the availability zone we want to use exists.
    fake_ec2.should_receive('get_all_zones').with_args('my-zone-1b') \
      .and_return('anything')

    # Pretend that a bad availability zone doesn't exist.
    fake_ec2.should_receive('get_all_zones').with_args('bad-zone-1b') \
      .and_raise(boto.exception.EC2ResponseError, 'baz', 'baz')

    # Pretend that we have one elastic IP allocated for use.
    fake_ec2.should_receive('get_all_addresses').with_args('GOOD.IP.ADDRESS') \
      .and_return('anything')

    # Pretend that asking for a bad elastic IP doesn't work.
    fake_ec2.should_receive('get_all_addresses').with_args('BAD.IP.ADDRESS') \
      .and_raise(boto.exception.EC2ResponseError, 'baz', 'baz')

    fake_price = flexmock(name='fake_price', price=1.00)
    fake_ec2.should_receive('get_spot_price_history').and_return([fake_price])

    flexmock(boto)
    flexmock(boto.ec2)
    boto.ec2.should_receive('connect_to_region').with_args('my-zone-1',
      aws_access_key_id='baz', aws_secret_access_key='baz').and_return(fake_ec2)
    boto.ec2.should_receive('connect_to_region').with_args('bad-zone-1',
      aws_access_key_id='baz', aws_secret_access_key='baz').and_return(fake_ec2)
    boto.should_receive('connect_euca').and_return(fake_ec2)
예제 #10
0
    def setUp(self):
        self.keyname = "boobazblargfoo"
        self.function = "appscale-remove-app"

        # mock out any writing to stdout
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('log').and_return()
        AppScaleLogger.should_receive('success').and_return()

        # mock out all sleeping
        flexmock(time)
        time.should_receive('sleep').and_return()
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.function = "appscale-remove-app"

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()
    AppScaleLogger.should_receive('success').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()
    def setUp(self):
        self.keyname = "boobazblargfoo"
        self.function = "appscale-upload-app"
        self.app_dir = "/tmp/baz/gbaz"

        # mock out the check to make sure our app is a directory
        flexmock(os.path)
        os.path.should_call('isdir')
        os.path.should_receive('isdir').with_args(
            self.app_dir).and_return(True)

        # mock out any writing to stdout
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('log').and_return()
        AppScaleLogger.should_receive('success').and_return()

        # mock out all sleeping
        flexmock(time)
        time.should_receive('sleep').and_return()

        local_state = flexmock(LocalState)
        local_state.should_receive('shell').and_return()

        # throw some default mocks together for when invoking via shell succeeds
        # and when it fails
        self.fake_temp_file = flexmock(name='fake_temp_file')
        self.fake_temp_file.should_receive('read').and_return('boo out')
        self.fake_temp_file.should_receive('close').and_return()
        self.fake_temp_file.should_receive('seek').with_args(0).and_return()

        flexmock(tempfile)
        tempfile.should_receive('NamedTemporaryFile').and_return(
            self.fake_temp_file)

        self.success = flexmock(name='success', returncode=0)
        self.success.should_receive('wait').and_return(0)

        self.failed = flexmock(name='success', returncode=1)
        self.failed.should_receive('wait').and_return(1)

        # mock out generating a random app dir, for later mocks
        flexmock(uuid)
        uuid.should_receive('uuid4').and_return('1234')
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.function = "appscale-upload-app"
    self.app_dir = "/tmp/baz/gbaz"

    # mock out the check to make sure our app is a directory
    flexmock(os.path)
    os.path.should_call('isdir')
    os.path.should_receive('isdir').with_args(self.app_dir).and_return(True)

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()
    AppScaleLogger.should_receive('success').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()

    local_state = flexmock(LocalState)
    local_state.should_receive('shell').and_return()

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()
    self.fake_temp_file.should_receive('seek').with_args(0).and_return()

    flexmock(tempfile)
    tempfile.should_receive('NamedTemporaryFile').and_return(self.fake_temp_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='success', returncode=1)
    self.failed.should_receive('wait').and_return(1)

    # mock out generating a random app dir, for later mocks
    flexmock(uuid)
    uuid.should_receive('uuid4').and_return('1234')
    def test_generate_crash_log_on_unsupported_locale(self):
        crashlog_suffix = '123456'
        flexmock(uuid)
        uuid.should_receive('uuid4').and_return(crashlog_suffix)

        exception_class = 'Exception'
        exception_message = 'baz message'
        exception = Exception(exception_message)
        stacktrace = "\n".join([
            'Traceback (most recent call last):',
            '  File "<stdin>", line 2, in <module>',
            '{0}: {1}'.format(exception_class, exception_message)
        ])

        # Mock out grabbing our system's information
        flexmock(platform)
        platform.should_receive('platform').and_return("MyOS")
        platform.should_receive('python_implementation').and_return("MyPython")

        flexmock(locale)
        locale.should_receive('setlocale').and_raise(locale.Error)

        # Mock out writing it to the crash log file
        expected = '{0}log-{1}'.format(LocalState.LOCAL_APPSCALE_PATH,
                                       crashlog_suffix)

        fake_file = flexmock(name='fake_file')
        fake_file.should_receive('write').with_args(str)

        fake_builtins = flexmock(sys.modules['__builtin__'])
        fake_builtins.should_call('open')  # set the fall-through
        fake_builtins.should_receive('open').with_args(
            expected, 'w').and_return(fake_file)

        # mock out printing the crash log message
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('warn')

        actual = LocalState.generate_crash_log(exception, stacktrace)
        self.assertEquals(expected, actual)
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.function = "appscale-run-instances"

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()
    AppScaleLogger.should_receive('success').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('seek').with_args(0).and_return()
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()

    self.fake_input_file = flexmock(name='fake_input_file')
    self.fake_input_file.should_receive('seek').with_args(0).and_return()
    self.fake_input_file.should_receive('write').and_return()
    self.fake_input_file.should_receive('read').and_return('boo out')
    self.fake_input_file.should_receive('close').and_return()

    flexmock(tempfile)
    tempfile.should_receive('NamedTemporaryFile')\
      .and_return(self.fake_temp_file)
    tempfile.should_receive('TemporaryFile').and_return(self.fake_input_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='failed', returncode=1)
    self.failed.should_receive('wait').and_return(1)

    # throw in some mocks that assume our EC2 environment variables are set
    for credential in EC2Agent.REQUIRED_EC2_CREDENTIALS:
      os.environ[credential] = "baz"
예제 #16
0
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.function = "appscale-run-instances"

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()
    AppScaleLogger.should_receive('success').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('seek').with_args(0).and_return()
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()

    self.fake_input_file = flexmock(name='fake_input_file')
    self.fake_input_file.should_receive('seek').with_args(0).and_return()
    self.fake_input_file.should_receive('write').and_return()
    self.fake_input_file.should_receive('read').and_return('boo out')
    self.fake_input_file.should_receive('close').and_return()

    flexmock(tempfile)
    tempfile.should_receive('NamedTemporaryFile')\
      .and_return(self.fake_temp_file)
    tempfile.should_receive('TemporaryFile').and_return(self.fake_input_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='failed', returncode=1)
    self.failed.should_receive('wait').and_return(1)

    # throw in some mocks that assume our EC2 environment variables are set
    for credential in EC2Agent.REQUIRED_EC2_CREDENTIALS:
      os.environ[credential] = "baz"
예제 #17
0
  def test_generate_crash_log_on_unsupported_locale(self):
    crashlog_suffix = '123456'
    flexmock(uuid)
    uuid.should_receive('uuid4').and_return(crashlog_suffix)

    exception_class = 'Exception'
    exception_message = 'baz message'
    exception = Exception(exception_message)
    stacktrace = "\n".join(['Traceback (most recent call last):',
      '  File "<stdin>", line 2, in <module>',
      '{0}: {1}'.format(exception_class, exception_message)])

    # Mock out grabbing our system's information
    flexmock(platform)
    platform.should_receive('platform').and_return("MyOS")
    platform.should_receive('python_implementation').and_return("MyPython")

    flexmock(locale)
    locale.should_receive('setlocale').and_raise(locale.Error)

    # Mock out writing it to the crash log file
    expected = '{0}log-{1}'.format(LocalState.LOCAL_APPSCALE_PATH,
      crashlog_suffix)

    fake_file = flexmock(name='fake_file')
    fake_file.should_receive('write').with_args(str)

    fake_builtins = flexmock(sys.modules['__builtin__'])
    fake_builtins.should_call('open')  # set the fall-through
    fake_builtins.should_receive('open').with_args(expected, 'w').and_return(
      fake_file)

    # mock out printing the crash log message
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('warn')

    actual = LocalState.generate_crash_log(exception, stacktrace)
    self.assertEquals(expected, actual)
    def setUp(self):
        self.keyname = "boobazblargfoo"
        self.function = "appscale-relocate-app"
        self.appid = 'my-crazy-app'

        # mock out any writing to stdout
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('log').and_return()
        AppScaleLogger.should_receive('success').and_return()
        AppScaleLogger.should_receive('warn').and_return()

        # mock out all sleeping
        flexmock(time)
        time.should_receive('sleep').and_return()

        # mock out reading the locations.json file, and slip in our own json
        flexmock(os.path)
        os.path.should_call('exists')  # set the fall-through
        os.path.should_receive('exists').with_args(
            LocalState.get_locations_json_location(
                self.keyname)).and_return(True)

        fake_nodes_json = flexmock(name="fake_nodes_json")
        fake_nodes_json.should_receive('read').and_return(
            json.dumps([{
                "public_ip": "public1",
                "private_ip": "private1",
                "jobs": ["shadow", "login"]
            }]))
        fake_nodes_json.should_receive('write').and_return()
        builtins = flexmock(sys.modules['__builtin__'])
        builtins.should_call('open')  # set the fall-through
        builtins.should_receive('open').with_args(
          LocalState.get_locations_json_location(self.keyname), 'r') \
          .and_return(fake_nodes_json)

        # put in a mock for reading the secret file
        secret_key_location = LocalState.get_secret_key_location(self.keyname)
        fake_secret = flexmock(name="fake_secret")
        fake_secret.should_receive('read').and_return('the secret')
        builtins.should_receive('open').with_args(secret_key_location, 'r') \
          .and_return(fake_secret)
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.function = "appscale-relocate-app"
    self.appid = 'my-crazy-app'

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()
    AppScaleLogger.should_receive('success').and_return()
    AppScaleLogger.should_receive('warn').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()

    # mock out reading the locations.json file, and slip in our own json
    flexmock(os.path)
    os.path.should_call('exists')  # set the fall-through
    os.path.should_receive('exists').with_args(
      LocalState.get_locations_json_location(self.keyname)).and_return(True)

    fake_nodes_json = flexmock(name="fake_nodes_json")
    fake_nodes_json.should_receive('read').and_return(json.dumps([{
      "public_ip" : "public1",
      "private_ip" : "private1",
      "jobs" : ["shadow", "login"]
    }]))
    fake_nodes_json.should_receive('write').and_return()
    builtins = flexmock(sys.modules['__builtin__'])
    builtins.should_receive('open').with_args(
      LocalState.get_locations_json_location(self.keyname), 'r') \
      .and_return(fake_nodes_json)

    # put in a mock for reading the secret file
    builtins.should_call('open')  # set the fall-through

    secret_key_location = LocalState.get_secret_key_location(self.keyname)
    fake_secret = flexmock(name="fake_secret")
    fake_secret.should_receive('read').and_return('the secret')
    builtins.should_receive('open').with_args(secret_key_location, 'r') \
      .and_return(fake_secret)
    def setUp(self):
        # mock out all logging, since it clutters our output
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive("log").and_return()

        # mock out all sleeps, as they aren't necessary for unit testing
        flexmock(time)
        time.should_receive("sleep").and_return()

        # set up some fake options so that we don't have to generate them via
        # ParseArgs
        self.options = flexmock(
            infrastructure="ec2",
            group="boogroup",
            machine="ami-ABCDEFG",
            instance_type="m1.large",
            keyname="bookey",
            table="cassandra",
            verbose=False,
            test=False,
            use_spot_instances=False,
            zone="my-zone-1b",
        )
        self.my_id = "12345"
        self.node_layout = NodeLayout(self.options)

        # set up phony AWS credentials for each test
        # ones that test not having them present can
        # remove them
        for credential in EucalyptusAgent.REQUIRED_EC2_CREDENTIALS:
            os.environ[credential] = "baz"
        os.environ["EC2_URL"] = "http://boo"

        # mock out calls to EC2
        # begin by assuming that our ssh keypair doesn't exist, and thus that we
        # need to create it
        key_contents = "key contents here"
        fake_key = flexmock(name="fake_key", material=key_contents)
        fake_key.should_receive("save").with_args(os.environ["HOME"] + "/.appscale").and_return(None)

        fake_ec2 = flexmock(name="fake_ec2")
        fake_ec2.should_receive("get_key_pair").with_args("bookey").and_return(None)
        fake_ec2.should_receive("create_key_pair").with_args("bookey").and_return(fake_key)

        # mock out writing the secret key
        builtins = flexmock(sys.modules["__builtin__"])
        builtins.should_call("open")  # set the fall-through

        secret_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.secret"
        fake_secret = flexmock(name="fake_secret")
        fake_secret.should_receive("write").and_return()
        builtins.should_receive("open").with_args(secret_key_location, "w").and_return(fake_secret)

        # also, mock out the keypair writing and chmod'ing
        ssh_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.key"
        fake_file = flexmock(name="fake_file")
        fake_file.should_receive("write").with_args(key_contents).and_return()

        builtins.should_receive("open").with_args(ssh_key_location, "w").and_return(fake_file)

        flexmock(os)
        os.should_receive("chmod").with_args(ssh_key_location, 0600).and_return()

        # next, assume there are no security groups up at first, but then it gets
        # created.
        udp_rule = flexmock(from_port=1, to_port=65535, ip_protocol="udp")
        tcp_rule = flexmock(from_port=1, to_port=65535, ip_protocol="tcp")
        icmp_rule = flexmock(from_port=-1, to_port=-1, ip_protocol="icmp")
        group = flexmock(name="boogroup", rules=[tcp_rule, udp_rule, icmp_rule])
        fake_ec2.should_receive("get_all_security_groups").with_args().and_return([])
        fake_ec2.should_receive("get_all_security_groups").with_args("boogroup").and_return([group])

        # and then assume we can create and open our security group fine
        fake_ec2.should_receive("create_security_group").with_args("boogroup", "AppScale security group").and_return()
        fake_ec2.should_receive("authorize_security_group").and_return()

        # next, add in mocks for run_instances
        # the first time around, let's say that no machines are running
        # the second time around, let's say that our machine is pending
        # and that it's up the third time around
        fake_pending_instance = flexmock(state="pending")
        fake_pending_reservation = flexmock(instances=fake_pending_instance)

        fake_running_instance = flexmock(
            state="running", key_name="bookey", id="i-12345678", public_dns_name="public1", private_dns_name="private1"
        )
        fake_running_reservation = flexmock(instances=fake_running_instance)

        fake_ec2.should_receive("get_all_instances").and_return([]).and_return([fake_pending_reservation]).and_return(
            [fake_running_reservation]
        )

        # next, assume that our run_instances command succeeds
        fake_ec2.should_receive("run_instances").and_return()

        # finally, inject our mocked EC2
        flexmock(boto)
        boto.should_receive("connect_ec2").and_return(fake_ec2)

        # assume that ssh comes up on the third attempt
        fake_socket = flexmock(name="fake_socket")
        fake_socket.should_receive("connect").with_args(("public1", RemoteHelper.SSH_PORT)).and_raise(
            Exception
        ).and_raise(Exception).and_return(None)
        flexmock(socket)
        socket.should_receive("socket").and_return(fake_socket)

        # throw some default mocks together for when invoking via shell succeeds
        # and when it fails
        self.fake_temp_file = flexmock(name="fake_temp_file")
        self.fake_temp_file.should_receive("seek").with_args(0).and_return()
        self.fake_temp_file.should_receive("read").and_return("boo out")
        self.fake_temp_file.should_receive("close").and_return()

        flexmock(tempfile)
        tempfile.should_receive("NamedTemporaryFile").and_return(self.fake_temp_file)

        self.success = flexmock(name="success", returncode=0)
        self.success.should_receive("wait").and_return(0)

        self.failed = flexmock(name="success", returncode=1)
        self.failed.should_receive("wait").and_return(1)

        # assume that root login isn't already enabled
        local_state = flexmock(LocalState)
        local_state.should_receive("shell").with_args(re.compile("^ssh .*root"), False, 1, stdin="ls").and_return(
            "Please login as the ubuntu user rather than root user."
        )

        # and assume that we can ssh in as ubuntu to enable root login
        local_state = flexmock(LocalState)
        local_state.should_receive("shell").with_args(re.compile("^ssh .*ubuntu"), False, 5).and_return()

        # also assume that we can scp over our ssh keys
        local_state.should_receive("shell").with_args(re.compile("scp .*/root/.ssh/id_"), False, 5).and_return()

        local_state.should_receive("shell").with_args(
            re.compile("scp .*/root/.appscale/bookey.key"), False, 5
        ).and_return()
    def setUp(self):
        self.keyname = "boobazblargfoo"
        self.group = "bazgroup"
        self.function = "appscale-run-instances"

        # mock out any writing to stdout
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('log').and_return()
        AppScaleLogger.should_receive('success').and_return()

        # mock out all sleeping
        flexmock(time)
        time.should_receive('sleep').and_return()

        # pretend we have an appscalefile at the right location, and that it
        # specifies the keyname and group
        appscalefile_path = os.getcwd() + os.sep + "AppScalefile"
        flexmock(os.path)
        os.path.should_call('exists')
        os.path.should_receive('exists').with_args(appscalefile_path) \
          .and_return(True)

        appscalefile_contents = """
keyname: {0}
group: {1}
""".format(self.keyname, self.group)

        self.builtins = flexmock(sys.modules['__builtin__'])
        self.builtins.should_call('open')  # set the fall-through
        fake_appscalefile = flexmock(name="fake_appscalefile")
        fake_appscalefile.should_receive('read').and_return(
            appscalefile_contents)
        fake_appscalefile.should_receive('write').and_return()
        self.builtins.should_receive('open').with_args(appscalefile_path, 'r') \
          .and_return(fake_appscalefile)
        self.builtins.should_receive('open').with_args(appscalefile_path, 'w') \
          .and_return(fake_appscalefile)

        # throw some default mocks together for when invoking via shell succeeds
        # and when it fails
        self.fake_temp_file = flexmock(name='fake_temp_file')
        self.fake_temp_file.should_receive('seek').with_args(0).and_return()
        self.fake_temp_file.should_receive('read').and_return('boo out')
        self.fake_temp_file.should_receive('close').and_return()

        self.fake_input_file = flexmock(name='fake_input_file')
        self.fake_input_file.should_receive('seek').with_args(0).and_return()
        self.fake_input_file.should_receive('write').and_return()
        self.fake_input_file.should_receive('read').and_return('boo out')
        self.fake_input_file.should_receive('close').and_return()

        flexmock(tempfile)
        tempfile.should_receive('NamedTemporaryFile')\
          .and_return(self.fake_temp_file)
        tempfile.should_receive('TemporaryFile').and_return(
            self.fake_input_file)

        self.success = flexmock(name='success', returncode=0)
        self.success.should_receive('wait').and_return(0)

        self.failed = flexmock(name='failed', returncode=1)
        self.failed.should_receive('wait').and_return(1)

        # throw in some mocks that assume our EC2 environment variables are set
        for credential in EC2Agent.REQUIRED_EC2_CREDENTIALS:
            os.environ[credential] = "baz"

        # mock out interactions with AWS
        self.fake_ec2 = flexmock(name='fake_ec2')

        # And add in mocks for libraries most of the tests mock out
        self.local_state = flexmock(LocalState)
  def setUp(self):
    self.keyname = "boobazblargfoo"
    self.group = "bazgroup"
    self.function = "appscale-run-instances"

    # mock out any writing to stdout
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()
    AppScaleLogger.should_receive('success').and_return()

    # mock out all sleeping
    flexmock(time)
    time.should_receive('sleep').and_return()

    # pretend we have an appscalefile at the right location, and that it
    # specifies the keyname and group
    appscalefile_path = os.getcwd() + os.sep + "AppScalefile"
    flexmock(os.path)
    os.path.should_call('exists')
    os.path.should_receive('exists').with_args(appscalefile_path) \
      .and_return(True)

    appscalefile_contents = """
keyname: {0}
group: {1}
""".format(self.keyname, self.group)

    self.builtins = flexmock(sys.modules['__builtin__'])
    self.builtins.should_call('open')  # set the fall-through
    fake_appscalefile = flexmock(name="fake_appscalefile")
    fake_appscalefile.should_receive('read').and_return(appscalefile_contents)
    fake_appscalefile.should_receive('write').and_return()
    self.builtins.should_receive('open').with_args(appscalefile_path, 'r') \
      .and_return(fake_appscalefile)
    self.builtins.should_receive('open').with_args(appscalefile_path, 'w') \
      .and_return(fake_appscalefile)

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('seek').with_args(0).and_return()
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()

    self.fake_input_file = flexmock(name='fake_input_file')
    self.fake_input_file.should_receive('seek').with_args(0).and_return()
    self.fake_input_file.should_receive('write').and_return()
    self.fake_input_file.should_receive('read').and_return('boo out')
    self.fake_input_file.should_receive('close').and_return()

    flexmock(tempfile)
    tempfile.should_receive('NamedTemporaryFile')\
      .and_return(self.fake_temp_file)
    tempfile.should_receive('TemporaryFile').and_return(self.fake_input_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='failed', returncode=1)
    self.failed.should_receive('wait').and_return(1)

    # throw in some mocks that assume our EC2 environment variables are set
    for credential in EC2Agent.REQUIRED_EC2_CREDENTIALS:
      os.environ[credential] = "baz"

    # mock out interactions with AWS
    self.fake_ec2 = flexmock(name='fake_ec2')

    # And add in mocks for libraries most of the tests mock out
    self.local_state = flexmock(LocalState)
    def setUp(self):
        self.cloud_argv = [
            '--min', '1', '--max', '1', '--group', 'blargscale',
            '--infrastructure', 'ec2', '--machine', 'ami-ABCDEFG', '--zone',
            'my-zone-1b'
        ]
        self.cluster_argv = ['--ips', 'ips.yaml']
        self.function = "appscale-run-instances"

        # mock out all logging, since it clutters our output
        flexmock(AppScaleLogger)
        AppScaleLogger.should_receive('log').and_return()

        # set up phony AWS credentials for each test
        # ones that test not having them present can
        # remove them
        for credential in EucalyptusAgent.REQUIRED_EC2_CREDENTIALS:
            os.environ[credential] = "baz"
        os.environ['EC2_URL'] = "http://boo"

        # pretend that our credentials are valid.
        fake_ec2 = flexmock(name="fake_ec2")
        fake_ec2.should_receive('get_all_instances')

        # similarly, pretend that our image does exist in EC2
        # and Euca
        fake_ec2.should_receive('get_image').with_args('ami-ABCDEFG') \
          .and_return()
        fake_ec2.should_receive('get_image').with_args('emi-ABCDEFG') \
          .and_return('anything')

        # Slip in mocks that assume our EBS volume exists in EC2.
        fake_ec2.should_receive('get_all_volumes').with_args(['vol-ABCDEFG']) \
          .and_return('anything')

        # Also pretend that the availability zone we want to use exists.
        fake_ec2.should_receive('get_all_zones').with_args('my-zone-1b') \
          .and_return('anything')

        # Pretend that a bad availability zone doesn't exist.
        fake_ec2.should_receive('get_all_zones').with_args('bad-zone-1b') \
          .and_raise(boto.exception.EC2ResponseError, 'baz', 'baz')

        # Pretend that we have one elastic IP allocated for use.
        fake_ec2.should_receive('get_all_addresses').with_args('GOOD.IP.ADDRESS') \
          .and_return('anything')

        # Pretend that asking for a bad elastic IP doesn't work.
        fake_ec2.should_receive('get_all_addresses').with_args('BAD.IP.ADDRESS') \
          .and_raise(boto.exception.EC2ResponseError, 'baz', 'baz')

        fake_price = flexmock(name='fake_price', price=1.00)
        fake_ec2.should_receive('get_spot_price_history').and_return(
            [fake_price])

        flexmock(boto)
        flexmock(boto.ec2)
        boto.ec2.should_receive('connect_to_region').with_args(
            'my-zone-1', aws_access_key_id='baz',
            aws_secret_access_key='baz').and_return(fake_ec2)
        boto.ec2.should_receive('connect_to_region').with_args(
            'bad-zone-1', aws_access_key_id='baz',
            aws_secret_access_key='baz').and_return(fake_ec2)
        boto.should_receive('connect_euca').and_return(fake_ec2)
예제 #24
0
  def setUp(self):
    # mock out all logging, since it clutters our output
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()

    # mock out all sleeps, as they aren't necessary for unit testing
    flexmock(time)
    time.should_receive('sleep').and_return()

    # set up some fake options so that we don't have to generate them via
    # ParseArgs
    self.options = flexmock(infrastructure='ec2', group='boogroup',
      machine='ami-ABCDEFG', instance_type='m1.large', keyname='bookey',
      table='cassandra', verbose=False)
    self.node_layout = NodeLayout(self.options)

    # mock out calls to EC2
    # begin by assuming that our ssh keypair doesn't exist, and thus that we
    # need to create it
    key_contents = "key contents here"
    fake_key = flexmock(name="fake_key", material=key_contents)

    fake_ec2 = flexmock(name="fake_ec2")
    fake_ec2.should_receive('get_key_pair').with_args('bookey') \
      .and_return(None)
    fake_ec2.should_receive('create_key_pair').with_args('bookey') \
      .and_return(fake_key)

    # mock out writing the secret key
    builtins = flexmock(sys.modules['__builtin__'])
    builtins.should_call('open')  # set the fall-through

    secret_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.secret"
    fake_secret = flexmock(name="fake_secret")
    fake_secret.should_receive('write').and_return()
    builtins.should_receive('open').with_args(secret_key_location, 'w') \
      .and_return(fake_secret)

    # also, mock out the keypair writing and chmod'ing
    ssh_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.key"
    fake_file = flexmock(name="fake_file")
    fake_file.should_receive('write').with_args(key_contents).and_return()

    builtins.should_receive('open').with_args(ssh_key_location, 'w') \
      .and_return(fake_file)

    flexmock(os)
    os.should_receive('chmod').with_args(ssh_key_location, 0600).and_return()

    # next, assume there are no security groups up yet
    fake_ec2.should_receive('get_all_security_groups').and_return([])

    # and then assume we can create and open our security group fine
    fake_ec2.should_receive('create_security_group').with_args('boogroup',
      'AppScale security group').and_return()
    fake_ec2.should_receive('authorize_security_group').and_return()

    # next, add in mocks for run_instances
    # the first time around, let's say that no machines are running
    # the second time around, let's say that our machine is pending
    # and that it's up the third time around
    fake_pending_instance = flexmock(state='pending')
    fake_pending_reservation = flexmock(instances=fake_pending_instance)

    fake_running_instance = flexmock(state='running', key_name='bookey',
      id='i-12345678', public_dns_name='public1', private_dns_name='private1')
    fake_running_reservation = flexmock(instances=fake_running_instance)

    fake_ec2.should_receive('get_all_instances').and_return([]) \
      .and_return([fake_pending_reservation]) \
      .and_return([fake_running_reservation])

    # next, assume that our run_instances command succeeds
    fake_ec2.should_receive('run_instances').and_return()

    # finally, inject our mocked EC2
    flexmock(boto)
    boto.should_receive('connect_ec2').with_args('baz', 'baz').and_return(fake_ec2)

    # assume that ssh comes up on the third attempt
    fake_socket = flexmock(name='fake_socket')
    fake_socket.should_receive('connect').with_args(('public1',
      RemoteHelper.SSH_PORT)).and_raise(Exception).and_raise(Exception) \
      .and_return(None)
    flexmock(socket)
    socket.should_receive('socket').and_return(fake_socket)

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()

    flexmock(tempfile)
    tempfile.should_receive('TemporaryFile').and_return(self.fake_temp_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='success', returncode=1)
    self.failed.should_receive('wait').and_return(1)

    # and assume that we can ssh in as ubuntu to enable root login, but that
    # it fails the first time
    flexmock(subprocess)
    subprocess.should_receive('Popen').with_args(re.compile('ubuntu'), \
      shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
      .and_return(self.failed).and_return(self.success)

    # also assume that we can scp over our ssh keys, but that it fails the first
    # time
    subprocess.should_receive('Popen').with_args(re.compile('/root/.ssh/id_'),
      shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
      .and_return(self.failed).and_return(self.success)

    subprocess.should_receive('Popen').with_args(re.compile(
      '/root/.appscale/bookey.key'),
      shell=True, stdout=self.fake_temp_file, stderr=subprocess.STDOUT) \
      .and_return(self.failed).and_return(self.success)
  def setUp(self):
    # mock out all logging, since it clutters our output
    flexmock(AppScaleLogger)
    AppScaleLogger.should_receive('log').and_return()

    # mock out all sleeps, as they aren't necessary for unit testing
    flexmock(time)
    time.should_receive('sleep').and_return()

    # set up some fake options so that we don't have to generate them via
    # ParseArgs
    self.options = flexmock(infrastructure='ec2', group='boogroup',
      machine='ami-ABCDEFG', instance_type='m1.large', keyname='bookey',
      table='cassandra', verbose=False, test=False, use_spot_instances=False,
      zone='my-zone-1b', static_ip=None)
    self.my_id = "12345"
    self.node_layout = NodeLayout(self.options)

    # set up phony AWS credentials for each test
    # ones that test not having them present can
    # remove them
    for credential in EucalyptusAgent.REQUIRED_EC2_CREDENTIALS:
      os.environ[credential] = "baz"
    os.environ['EC2_URL'] = "http://boo"

    # mock out calls to EC2
    # begin by assuming that our ssh keypair doesn't exist, and thus that we
    # need to create it
    key_contents = "key contents here"
    fake_key = flexmock(name="fake_key", material=key_contents)
    fake_key.should_receive('save').with_args(os.environ['HOME']+'/.appscale').and_return(None)

    fake_ec2 = flexmock(name="fake_ec2")
    fake_ec2.should_receive('get_key_pair').with_args('bookey') \
      .and_return(None)
    fake_ec2.should_receive('create_key_pair').with_args('bookey') \
      .and_return(fake_key)

    # mock out writing the secret key
    builtins = flexmock(sys.modules['__builtin__'])
    builtins.should_call('open')  # set the fall-through

    secret_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.secret"
    fake_secret = flexmock(name="fake_secret")
    fake_secret.should_receive('write').and_return()
    builtins.should_receive('open').with_args(secret_key_location, 'w') \
      .and_return(fake_secret)

    # also, mock out the keypair writing and chmod'ing
    ssh_key_location = LocalState.LOCAL_APPSCALE_PATH + "bookey.key"
    fake_file = flexmock(name="fake_file")
    fake_file.should_receive('write').with_args(key_contents).and_return()

    builtins.should_receive('open').with_args(ssh_key_location, 'w') \
      .and_return(fake_file)

    flexmock(os)
    os.should_receive('chmod').with_args(ssh_key_location, 0600).and_return()

    # next, assume there are no security groups up at first, but then it gets
    # created.
    udp_rule = flexmock(from_port=1, to_port=65535, ip_protocol='udp')
    tcp_rule = flexmock(from_port=1, to_port=65535, ip_protocol='tcp')
    icmp_rule = flexmock(from_port=-1, to_port=-1, ip_protocol='icmp')
    group = flexmock(name='boogroup', rules=[tcp_rule, udp_rule, icmp_rule])
    fake_ec2.should_receive('get_all_security_groups').with_args().and_return([])
    fake_ec2.should_receive('get_all_security_groups').with_args('boogroup').and_return([group])

    # and then assume we can create and open our security group fine
    fake_ec2.should_receive('create_security_group').with_args('boogroup',
      'AppScale security group').and_return()
    fake_ec2.should_receive('authorize_security_group').and_return()

    # next, add in mocks for run_instances
    # the first time around, let's say that no machines are running
    # the second time around, let's say that our machine is pending
    # and that it's up the third time around
    fake_pending_instance = flexmock(state='pending')
    fake_pending_reservation = flexmock(instances=fake_pending_instance)

    fake_running_instance = flexmock(state='running', key_name='bookey',
      id='i-12345678', public_dns_name='public1', private_dns_name='private1')
    fake_running_reservation = flexmock(instances=fake_running_instance)

    fake_ec2.should_receive('get_all_instances').and_return([]) \
      .and_return([]) \
      .and_return([fake_pending_reservation]) \
      .and_return([fake_running_reservation])

    # next, assume that our run_instances command succeeds
    fake_ec2.should_receive('run_instances').and_return()

    # finally, inject our mocked EC2
    flexmock(boto.ec2)
    boto.ec2.should_receive('connect_to_region').and_return(fake_ec2)

    # assume that ssh comes up on the third attempt
    fake_socket = flexmock(name='fake_socket')
    fake_socket.should_receive('connect').with_args(('public1',
      RemoteHelper.SSH_PORT)).and_raise(Exception).and_raise(Exception) \
      .and_return(None)
    flexmock(socket)
    socket.should_receive('socket').and_return(fake_socket)

    # throw some default mocks together for when invoking via shell succeeds
    # and when it fails
    self.fake_temp_file = flexmock(name='fake_temp_file')
    self.fake_temp_file.should_receive('seek').with_args(0).and_return()
    self.fake_temp_file.should_receive('read').and_return('boo out')
    self.fake_temp_file.should_receive('close').and_return()

    flexmock(tempfile)
    tempfile.should_receive('NamedTemporaryFile')\
      .and_return(self.fake_temp_file)

    self.success = flexmock(name='success', returncode=0)
    self.success.should_receive('wait').and_return(0)

    self.failed = flexmock(name='success', returncode=1)
    self.failed.should_receive('wait').and_return(1)

    # assume that root login isn't already enabled
    local_state = flexmock(LocalState)
    local_state.should_receive('shell') \
      .with_args(re.compile('^ssh .*root'), False, 1, stdin='ls') \
      .and_return(RemoteHelper.LOGIN_AS_UBUNTU_USER)

    # and assume that we can ssh in as ubuntu to enable root login
    local_state = flexmock(LocalState)
    local_state.should_receive('shell')\
      .with_args(re.compile('^ssh .*ubuntu'),False,5)\
      .and_return()

    # also assume that we can scp over our ssh keys
    local_state.should_receive('shell')\
      .with_args(re.compile('scp .*/root/.ssh/id_'),False,5)\
      .and_return()

    local_state.should_receive('shell')\
      .with_args(re.compile('scp .*/root/.appscale/bookey.key'),False,5)\
      .and_return()