Ejemplo n.º 1
0
    def setUp(self):
        self.fake_ec2 = flexmock(name='self.fake_ec2')
        self.fake_ec2.should_receive('get_key_pair')
        self.fake_ec2.should_receive('create_key_pair').with_args('bookeyname') \
          .and_return(KeyPair())
        self.fake_ec2.should_receive('get_all_security_groups').and_return([])
        self.fake_ec2.should_receive('create_security_group') \
          .with_args('boogroup', 'AppScale security group') \
          .and_return(SecurityGroup())
        self.fake_ec2.should_receive('authorize_security_group')

        instance = flexmock(name='instance',
                            private_dns_name='private-ip',
                            public_dns_name='public-ip',
                            id='i-id',
                            state='running',
                            key_name='bookeyname')

        self.fake_ec2.should_receive('terminate_instances').and_return(
            [instance])
        self.fake_ec2.should_receive('run_instances')

        flexmock(boto.ec2)
        boto.ec2.should_receive('connect_to_region').and_return(self.fake_ec2)

        (flexmock(utils).should_receive('get_secret').and_return('secret'))
        (flexmock(utils).should_receive('sleep').and_return())
        (flexmock(utils).should_receive('get_random_alphanumeric').and_return(
            '0000000000'))
        (flexmock(utils).should_receive('write_key_file').and_return())
Ejemplo n.º 2
0
    def setUp(self):
        (flexmock(EC2Connection).should_receive('get_key_pair').and_return(
            None))
        (flexmock(EC2Connection).should_receive('create_key_pair').with_args(
            'bookeyname').and_return(KeyPair()))
        (flexmock(EC2Connection).should_receive(
            'get_all_security_groups').and_return([]))
        (flexmock(
            EC2Connection).should_receive('create_security_group').with_args(
                'boogroup',
                'AppScale security group').and_return(SecurityGroup()))
        (flexmock(EC2Connection).should_receive(
            'authorize_security_group').and_return())
        reservation = Reservation()
        instance = Instance()
        instance.private_dns_name = 'private-ip'
        instance.public_dns_name = 'public-ip'
        instance.id = 'i-id'
        instance._state.name = 'running'
        instance.key_name = 'bookeyname'
        reservation.instances = [instance]
        (flexmock(EC2Connection).should_receive(
            'get_all_instances').and_return([]).and_return([reservation]))
        (flexmock(EC2Connection).should_receive(
            'terminate_instances').and_return([instance]))
        (flexmock(EC2Connection).should_receive('run_instances').and_return())

        (flexmock(utils).should_receive('get_secret').and_return('secret'))
        (flexmock(utils).should_receive('sleep').and_return())
        (flexmock(utils).should_receive('get_random_alphanumeric').and_return(
            '0000000000'))
        (flexmock(utils).should_receive('write_key_file').and_return())
Ejemplo n.º 3
0
    def setUp(self):
        self.factory = InfrastructureAgentFactory()

        self.fake_ec2 = flexmock(name='self.fake_ec2')
        self.fake_ec2.should_receive('get_key_pair')
        self.fake_ec2.should_receive('create_key_pair').with_args('bookeyname') \
            .and_return(KeyPair())
        self.fake_ec2.should_receive('get_all_security_groups').and_return([])
        self.fake_ec2.should_receive('create_security_group') \
            .with_args('boogroup', 'AppScale security group') \
            .and_return(SecurityGroup())
        self.fake_ec2.should_receive('authorize_security_group')

        instance = flexmock(name='instance',
                            private_dns_name='private-ip',
                            public_dns_name='public-ip',
                            id='i-id',
                            state='running',
                            key_name='bookeyname')

        self.fake_ec2.should_receive('terminate_instances').and_return(
            [instance])
        self.fake_ec2.should_receive('run_instances')

        flexmock(boto.ec2)
        boto.ec2.should_receive('connect_to_region').and_return(self.fake_ec2)
Ejemplo n.º 4
0
  def setUp(self):
    (flexmock(EC2Connection)
      .should_receive('get_key_pair')
      .and_return(None))
    (flexmock(EC2Connection)
      .should_receive('create_key_pair')
      .with_args('bookeyname')
      .and_return(KeyPair()))
    (flexmock(EC2Connection)
      .should_receive('get_all_security_groups')
      .and_return([]))
    (flexmock(EC2Connection)
      .should_receive('create_security_group')
      .with_args('boogroup', 'AppScale security group')
      .and_return(SecurityGroup()))
    (flexmock(EC2Connection)
      .should_receive('authorize_security_group')
      .and_return())
    reservation = Reservation()

    # the old implementation had a regression where public and private IPs
    # were getting sorted, and thus public ip1 would point to private ip 2.
    # to prevent this regression from resurfacing, set up the dns names so
    # that a sort would mess them up again.
    instance1 = Instance()
    instance1.public_dns_name = 'ABC-public-ip1'
    instance1.private_dns_name = 'DEF-private-ip1'
    instance1.id = 'i-id1'
    instance1._state.name = 'running'
    instance1.key_name = 'bookeyname'

    instance2 = Instance()
    instance2.public_dns_name = 'DEF-public-ip2'
    instance2.private_dns_name = 'ABC-private-ip2'
    instance2.id = 'i-id2'
    instance2._state.name = 'running'
    instance2.key_name = 'bookeyname'

    reservation.instances = [instance1, instance2]
    (flexmock(EC2Connection)
      .should_receive('get_all_instances')
      .and_return([])
      .and_return([reservation]))
    (flexmock(EC2Connection)
     .should_receive('run_instances')
     .and_return())

    (flexmock(utils)
      .should_receive('get_secret')
      .and_return('secret'))
    (flexmock(utils)
      .should_receive('sleep')
      .and_return())
    (flexmock(utils)
      .should_receive('get_random_alphanumeric')
      .and_return('0000000000'))
    (flexmock(utils)
      .should_receive('write_key_file')
      .and_return())
Ejemplo n.º 5
0
    def setUp(self):
        self.factory = InfrastructureAgentFactory()

        (flexmock(EC2Connection).should_receive('get_key_pair').and_return(
            None))
        (flexmock(EC2Connection).should_receive('create_key_pair').with_args(
            'bookeyname').and_return(KeyPair()))
        (flexmock(EC2Connection).should_receive(
            'get_all_security_groups').and_return([]))
        (flexmock(
            EC2Connection).should_receive('create_security_group').with_args(
                'boogroup',
                'AppScale security group').and_return(SecurityGroup()))
        (flexmock(EC2Connection).should_receive(
            'authorize_security_group').and_return())
        (flexmock(EC2Connection).should_receive('run_instances').and_return())
Ejemplo n.º 6
0
    def setUp(self):
        fake_ec2 = flexmock(name='fake_ec2')
        fake_ec2.should_receive('get_key_pair')
        fake_ec2.should_receive('create_key_pair').with_args('bookeyname') \
          .and_return(KeyPair())
        fake_ec2.should_receive('get_all_security_groups').and_return([])
        fake_ec2.should_receive('create_security_group') \
          .with_args('boogroup', 'AppScale security group') \
          .and_return(SecurityGroup())
        fake_ec2.should_receive('authorize_security_group')

        reservation = Reservation()
        instance = flexmock(name='instance',
                            private_dns_name='private-ip',
                            public_dns_name='public-ip',
                            id='i-id',
                            state='running',
                            key_name='bookeyname',
                            ip_address='public-ip',
                            private_ip_address='private-ip')
        new_instance = flexmock(name='new-instance',
                                private_dns_name='new-private-ip',
                                public_dns_name='new-public-ip',
                                id='new-i-id',
                                state='running',
                                key_name='bookeyname',
                                ip_address='new-public-ip',
                                private_ip_address='new-private-ip')
        reservation.instances = [instance]
        new_reservation = Reservation()
        new_reservation.instances = [instance, new_instance]
        fake_ec2.should_receive('get_all_instances').and_return([]) \
          .and_return([reservation]).and_return([reservation]) \
          .and_return([new_reservation]).and_return([new_reservation])

        fake_ec2.should_receive('terminate_instances').and_return([instance])
        fake_ec2.should_receive('request_spot_instances')

        flexmock(boto.ec2)
        boto.ec2.should_receive('connect_to_region').and_return(fake_ec2)

        (flexmock(utils).should_receive('get_secret').and_return('secret'))
        (flexmock(utils).should_receive('sleep').and_return())
        (flexmock(utils).should_receive('get_random_alphanumeric').and_return(
            '0000000000'))
        (flexmock(utils).should_receive('write_key_file').and_return())
Ejemplo n.º 7
0
    def setUp(self):
        (flexmock(EC2Connection).should_receive('get_key_pair').and_return(
            None))
        (flexmock(EC2Connection).should_receive('create_key_pair').with_args(
            'bookeyname').and_return(KeyPair()))
        (flexmock(EC2Connection).should_receive(
            'get_all_security_groups').and_return([]))
        (flexmock(
            EC2Connection).should_receive('create_security_group').with_args(
                'boogroup',
                'AppScale security group').and_return(SecurityGroup()))
        (flexmock(EC2Connection).should_receive(
            'authorize_security_group').and_return())
        (flexmock(EC2Connection).should_receive('run_instances').and_return())

        (flexmock(utils).should_receive('get_secret').and_return('secret'))
        (flexmock(utils).should_receive('sleep').and_return())
        (flexmock(utils).should_receive('get_random_alphanumeric').and_return(
            '0000000000'))
        (flexmock(utils).should_receive('write_key_file').and_return())
Ejemplo n.º 8
0
 def get_key_pair(self, keyname):
     kp = KeyPair()
     kp.name = keyname
     return kp