Exemplo n.º 1
0
    def testWithAdditionalSecurityGroupsBlocking(self):
        instance_starting = ecs.Instance(
            'i1', None, None, None, None, None, 'Starting', None,
            None, None, None, None, None, None)
        instance_running = ecs.Instance(
            'i1', None, None, None, None, None, 'Running', None,
            None, None, None, None, None, None)
        self.conn.create_instance(
            'image', 'type', 'sg1',
            hostname=None, instance_name=None, internet_charge_type=None,
            internet_max_bandwidth_in=None, internet_max_bandwidth_out=None,
            password=None, system_disk_type=None, data_disks=[]).AndReturn('i1')
        time.sleep(mox.IsA(int))
        self.conn.join_security_group('i1', 'sg2')
        self.conn.join_security_group('i1', 'sg3')
        self.conn.get({
            'Action': 'AllocatePublicIpAddress',
            'InstanceId': 'i1'
        })
        time.sleep(mox.IsA(int))
        self.conn.start_instance('i1')

        time.sleep(mox.IsA(int))
        self.conn.get_instance('i1').AndReturn(instance_starting)
        time.sleep(mox.IsA(int))
        self.conn.get_instance('i1').AndReturn(instance_starting)
        time.sleep(mox.IsA(int))
        self.conn.get_instance('i1').AndReturn(instance_running)

        self.mox.ReplayAll()
        self.assertEqual('i1', self.conn.create_and_start_instance(
            'image', 'type', 'sg1',
            additional_security_group_ids=['sg2', 'sg3']))
        self.mox.VerifyAll()
Exemplo n.º 2
0
    def testNotEqual(self):
        instance2 = ecs.Instance('id', 'name', 'imageId', 'regionId',
                                 'instanceType', 'hostname2', 'status',
                                 ['sg1', 'sg2'], ['ip1', 'ip2'],
                                 ['ip3', 'ip4'], 'accounting', 1, 1, self.now)

        self.assertNotEqual(self.instance1, instance2)
Exemplo n.º 3
0
 def setUp(self):
     self.now = datetime.datetime.now()
     self.instance1 = ecs.Instance('id', 'name', 'imageId', 'regionId',
                                   'instanceType', 'hostname', 'status',
                                   ['sg1', 'sg2'], ['ip1', 'ip2'],
                                   ['ip3', 'ip4'], 'accounting', 1, 1,
                                   self.now)
Exemplo n.º 4
0
    def testWithBlockingTimesOut(self):
        instance_starting = ecs.Instance(
            'i1', None, None, None, None, None, 'Starting', None,
            None, None, None, None, None, None)
        self.conn.create_instance(
            'image', 'type', 'sg1',
            hostname=None, instance_name=None, internet_charge_type=None,
            internet_max_bandwidth_in=None, internet_max_bandwidth_out=None,
            password=None, system_disk_type=None, data_disks=[]).AndReturn('i1')
        self.conn.get({
            'Action': 'AllocatePublicIpAddress',
            'InstanceId': 'i1'
        })
        time.sleep(mox.IsA(int))
        self.conn.start_instance('i1')

        time.sleep(mox.IsA(int)).MultipleTimes()
        self.conn.get_instance('i1').MultipleTimes().AndReturn(
            instance_starting)

        self.mox.ReplayAll()
        try:
            self.conn.create_and_start_instance('image', 'type', 'sg1')
            self.fail('Should throw error if times out')
        except ecs.Error as err:
            self.assertTrue('Timed out' in str(err))
        self.mox.VerifyAll()
Exemplo n.º 5
0
    def testSuccess(self):
        get_response = {
            'RegionId': 'r',
            'InstanceId': 'i1',
            'InstanceName': 'name',
            'ImageId': 'image',
            'InstanceType': 'type',
            'HostName': 'hostname',
            'Status': 'running',
            'InternetChargeType': 'chargetype',
            'InternetMaxBandwidthIn': '1',
            'InternetMaxBandwidthOut': '2',
            'CreationTime': '2014-02-05T00:52:32Z',
            'SecurityGroupIds': {'SecurityGroupId': ['sg1', 'sg2']},
            'PublicIpAddress': {'IpAddress': ['ip1', 'ip2']},
            'InnerIpAddress': {'IpAddress': ['ip3', 'ip4']}
        }
        expected_result = ecs.Instance(
            'i1', 'name', 'image', 'r', 'type', 'hostname', 'running',
            ['sg1', 'sg2'], ['ip1', 'ip2'], ['ip3', 'ip4'], 'chargetype', 1, 2,
            dateutil.parser.parse('2014-02-05T00:52:32Z'))
        self.conn.get({'Action': 'DescribeInstanceAttribute',
                       'InstanceId': 'i1'}).AndReturn(get_response)

        self.mox.ReplayAll()
        self.assertEqual(expected_result,
                         self.conn.get_instance('i1'))
        self.mox.VerifyAll()
Exemplo n.º 6
0
    def testEqual(self):
        instance2 = ecs.Instance('id', 'name', 'imageId', 'regionId',
                                 'instanceType', 'hostname', 'status',
                                 ['sg1', 'sg2'], ['ip1', 'ip2'],
                                 ['ip3', 'ip4'], 'accounting', 1, 1, self.now,
                                 self.now, 'p', 'desc', 'cluster', [], 'z')

        self.assertEqual(self.instance1, instance2)