def test_tag_subnet(self):
        cidr = '10.1.0.0/16'
        resp, data = self.client.CreateVpc(CidrBlock=cidr)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        vpc_id = data['Vpc']['VpcId']
        dv_clean = self.addResourceCleanUp(self.client.DeleteVpc, VpcId=vpc_id)

        cidr = '10.1.0.0/24'
        resp, data = self.client.CreateSubnet(VpcId=vpc_id, CidrBlock=cidr)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        subnet_id = data['Subnet']['SubnetId']
        res_clean = self.addResourceCleanUp(self.client.DeleteSubnet,
                                            SubnetId=subnet_id)

        def describe_func(*args, **kwargs):
            resp, data = self.client.DescribeSubnets(*args, **kwargs)
            self.assertEqual(200, resp.status_code,
                             base.EC2ErrorConverter(data))
            self.assertEqual(1, len(data['Subnets']))
            self.assertEqual(subnet_id, data['Subnets'][0]['SubnetId'])

        self._test_tag_resource(subnet_id, 'subnet', describe_func)

        resp, data = self.client.DeleteSubnet(SubnetId=subnet_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_subnet_waiter().wait_delete(subnet_id)

        resp, data = self.client.DeleteVpc(VpcId=vpc_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(dv_clean)
        self.get_vpc_waiter().wait_delete(vpc_id)
    def test_create_attach_internet_gateway(self):
        resp, data = self.client.CreateInternetGateway()
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        gw_id = data['InternetGateway']['InternetGatewayId']
        res_clean = self.addResourceCleanUp(self.client.DeleteInternetGateway,
                                            InternetGatewayId=gw_id)
        self.assertEmpty(data['InternetGateway'].get('Attachments', []))

        resp, data = self.client.AttachInternetGateway(VpcId=self.vpc_id,
                                                       InternetGatewayId=gw_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        resp, data = self.client.DetachInternetGateway(VpcId=self.vpc_id,
                                                       InternetGatewayId=gw_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        resp, data = self.client.DeleteInternetGateway(InternetGatewayId=gw_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)

        resp, data = self.client.DescribeInternetGateways(
            InternetGatewayIds=[gw_id])
        self.assertEqual(400, resp.status_code)
        self.assertEqual('InvalidInternetGatewayID.NotFound',
                         data['Error']['Code'])
    def test_tag_route_table(self):
        cidr = '10.1.0.0/16'
        resp, data = self.client.CreateVpc(CidrBlock=cidr)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        vpc_id = data['Vpc']['VpcId']
        dv_clean = self.addResourceCleanUp(self.client.DeleteVpc, VpcId=vpc_id)

        resp, data = self.client.CreateRouteTable(VpcId=vpc_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        rt_id = data['RouteTable']['RouteTableId']
        res_clean = self.addResourceCleanUp(self.client.DeleteRouteTable,
                                            RouteTableId=rt_id)

        def describe_func(*args, **kwargs):
            resp, data = self.client.DescribeRouteTables(*args, **kwargs)
            self.assertEqual(200, resp.status_code,
                             base.EC2ErrorConverter(data))
            self.assertEqual(1, len(data['RouteTables']))
            self.assertEqual(rt_id, data['RouteTables'][0]['RouteTableId'])

        self._test_tag_resource(rt_id, 'route-table', describe_func)

        resp, data = self.client.DeleteRouteTable(RouteTableId=rt_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)

        resp, data = self.client.DeleteVpc(VpcId=vpc_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(dv_clean)
        self.get_vpc_waiter().wait_delete(vpc_id)
    def test_tag_security_group(self):
        cidr = '10.1.0.0/16'
        resp, data = self.client.CreateVpc(CidrBlock=cidr)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        vpc_id = data['Vpc']['VpcId']
        dv_clean = self.addResourceCleanUp(self.client.DeleteVpc, VpcId=vpc_id)

        name = data_utils.rand_name('sgName')
        desc = data_utils.rand_name('sgDesc')
        resp, data = self.client.CreateSecurityGroup(VpcId=vpc_id,
                                                     GroupName=name,
                                                     Description=desc)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        group_id = data['GroupId']
        res_clean = self.addResourceCleanUp(self.client.DeleteSecurityGroup,
                                            GroupId=group_id)
        time.sleep(2)

        def describe_func(*args, **kwargs):
            resp, data = self.client.DescribeSecurityGroups(*args, **kwargs)
            self.assertEqual(200, resp.status_code,
                             base.EC2ErrorConverter(data))
            self.assertEqual(1, len(data['SecurityGroups']))
            self.assertEqual(group_id, data['SecurityGroups'][0]['GroupId'])

        self._test_tag_resource(group_id, 'security-group', describe_func)

        resp, data = self.client.DeleteSecurityGroup(GroupId=group_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)

        resp, data = self.client.DeleteVpc(VpcId=vpc_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(dv_clean)
        self.get_vpc_waiter().wait_delete(vpc_id)
    def test_tag_instance(self):
        instance_type = CONF.aws.instance_type
        image_id = CONF.aws.image_id
        resp, data = self.client.RunInstances(
            ImageId=image_id,
            InstanceType=instance_type,
            Placement={'AvailabilityZone': self.zone},
            MinCount=1,
            MaxCount=1)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.TerminateInstances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        def describe_func(*args, **kwargs):
            resp, data = self.client.DescribeInstances(*args, **kwargs)
            self.assertEqual(200, resp.status_code,
                             base.EC2ErrorConverter(data))
            self.assertEqual(1, len(data['Reservations']))
            self.assertEqual(1, len(data['Reservations'][0]['Instances']))
            self.assertEqual(
                instance_id,
                data['Reservations'][0]['Instances'][0]['InstanceId'])

        self._test_tag_resource(instance_id, 'instance', describe_func)

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
    def test_create_get_delete_tag(self):
        tag_key = data_utils.rand_name('tag-key')
        resp, data = self.client.CreateTags(Resources=[self.volume_id],
                                            Tags=[{
                                                'Key': tag_key,
                                                'Value': 'fake_value'
                                            }])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.addResourceCleanUp(self.client.DeleteTags,
                                Resources=[self.volume_id],
                                Tags=[{
                                    'Key': tag_key
                                }])

        resp, data = self.client.DescribeTags(
            Filters=[{
                'Name': 'resource-id',
                'Values': [self.volume_id]
            }])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(1, len(data['Tags']))

        resp, data = self.client.DeleteTags(Resources=[self.volume_id],
                                            Tags=[{
                                                'Key': tag_key
                                            }])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        resp, data = self.client.DescribeTags(
            Filters=[{
                'Name': 'resource-id',
                'Values': [self.volume_id]
            }])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(0, len(data['Tags']))
예제 #7
0
    def test_create_instance_with_private_ip(self):
        ip = '10.16.0.12'

        kwargs = {
            'ImageId': CONF.aws.image_id,
            'InstanceType': CONF.aws.instance_type,
            'MinCount': 1,
            'MaxCount': 1,
            'SubnetId': self.subnet_id,
            'PrivateIpAddress': ip
        }
        resp, data = self.client.RunInstances(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.TerminateInstances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        instance = self.get_instance(instance_id)
        self.assertEqual(ip, instance['PrivateIpAddress'])

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
    def test_tag_dhcp_options(self):
        kwargs = {
            'DhcpConfigurations': [
                {
                    'Key': 'domain-name',
                    'Values': ['my.com']
                },
            ],
        }
        resp, data = self.client.CreateDhcpOptions(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        options = data['DhcpOptions']
        res_id = options['DhcpOptionsId']
        res_clean = self.addResourceCleanUp(self.client.DeleteDhcpOptions,
                                            DhcpOptionsId=res_id)

        def describe_func(*args, **kwargs):
            resp, data = self.client.DescribeDhcpOptions(*args, **kwargs)
            self.assertEqual(200, resp.status_code,
                             base.EC2ErrorConverter(data))
            self.assertEqual(1, len(data['DhcpOptions']))
            self.assertEqual(res_id, data['DhcpOptions'][0]['DhcpOptionsId'])

        self._test_tag_resource(res_id, 'dhcp-options', describe_func)

        resp, data = self.client.DeleteDhcpOptions(DhcpOptionsId=res_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
    def test_dependency_subnet_to_vpc(self):
        resp, data = self.client.CreateVpc(CidrBlock=self.VPC_CIDR)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        vpc_id = data['Vpc']['VpcId']
        vpc_clean = self.addResourceCleanUp(self.client.DeleteVpc,
                                            VpcId=vpc_id)
        self.get_vpc_waiter().wait_available(vpc_id)

        cidr = self.BASE_CIDR + '/24'
        resp, data = self.client.CreateSubnet(VpcId=vpc_id, CidrBlock=cidr)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        subnet_id = data['Subnet']['SubnetId']
        res_clean = self.addResourceCleanUp(self.client.DeleteSubnet,
                                            SubnetId=subnet_id)
        self.get_subnet_waiter().wait_available(subnet_id)

        resp, data = self.client.DeleteVpc(VpcId=vpc_id)
        self.assertEqual(400, resp.status_code)
        self.assertEqual('DependencyViolation', data['Error']['Code'])

        resp, data = self.client.DeleteSubnet(SubnetId=subnet_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_subnet_waiter().wait_delete(subnet_id)

        self.client.DeleteVpc(VpcId=vpc_id)
        self.cancelResourceCleanUp(vpc_clean)
    def test_create_delete_subnet(self):
        cidr = self.BASE_CIDR + '/24'
        resp, data = self.client.CreateSubnet(VpcId=self.vpc_id,
                                              CidrBlock=cidr)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        subnet_id = data['Subnet']['SubnetId']
        res_clean = self.addResourceCleanUp(self.client.DeleteSubnet,
                                            SubnetId=subnet_id)
        self.assertEqual(cidr, data['Subnet']['CidrBlock'])
        self.assertIsNotNone(data['Subnet'].get('AvailableIpAddressCount'))

        self.get_subnet_waiter().wait_available(subnet_id)

        resp, data = self.client.DeleteSubnet(SubnetId=subnet_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_subnet_waiter().wait_delete(subnet_id)

        resp, data = self.client.DescribeSubnets(SubnetIds=[subnet_id])
        self.assertEqual(400, resp.status_code)
        self.assertEqual('InvalidSubnetID.NotFound', data['Error']['Code'])

        resp, data = self.client.DeleteSubnet(SubnetId=subnet_id)
        self.assertEqual(400, resp.status_code)
        self.assertEqual('InvalidSubnetID.NotFound', data['Error']['Code'])
    def test_create_delete_vpc(self):
        cidr = '10.1.0.0/16'
        resp, data = self.client.CreateVpc(CidrBlock=cidr)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        vpc_id = data['Vpc']['VpcId']
        dv_clean = self.addResourceCleanUp(self.client.DeleteVpc, VpcId=vpc_id)

        self.assertEqual(cidr, data['Vpc']['CidrBlock'])
        if CONF.aws.run_incompatible_tests:
            # NOTE(andrey-mp): not ready
            self.assertEqual('default', data['Vpc']['InstanceTenancy'])
        self.assertIsNotNone(data['Vpc'].get('DhcpOptionsId'))

        self.get_vpc_waiter().wait_available(vpc_id)

        resp, data = self.client.DeleteVpc(VpcId=vpc_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(dv_clean)
        self.get_vpc_waiter().wait_delete(vpc_id)

        resp, data = self.client.DescribeVpcs(VpcIds=[vpc_id])
        self.assertEqual(400, resp.status_code)
        self.assertEqual('InvalidVpcID.NotFound', data['Error']['Code'])

        resp, data = self.client.DeleteVpc(VpcId=vpc_id)
        self.assertEqual(400, resp.status_code)
        self.assertEqual('InvalidVpcID.NotFound', data['Error']['Code'])
    def test_import_key_pair(self):
        keyName = 'Test key'
        publicKey = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs"
                     "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd"
                     "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw"
                     "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P"
                     "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip"
                     "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt"
                     "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"
                     "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
                     "snSA8wzBx3A/8y9Pp1B test@ubuntu")
        resp, data = self.client.ImportKeyPair(KeyName=keyName,
                                               PublicKeyMaterial=publicKey)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        res_clean = self.addResourceCleanUp(self.client.DeleteKeyPair,
                                            KeyName=keyName)

        self.assertEqual(keyName, data['KeyName'])
        self.assertIsNotNone(data.get('KeyFingerprint'))
        self.assertGreater(len(data['KeyFingerprint']), 0)
        self.assertIsNone(data.get('KeyMaterial'))

        resp, data = self.client.DeleteKeyPair(KeyName=keyName)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
예제 #13
0
    def test_delete_subnet_with_network_interface(self):
        resp, data = self.client.CreateSubnet(VpcId=self.vpc_id,
                                              CidrBlock='10.7.1.0/28')
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        subnet_id = data['Subnet']['SubnetId']
        res_clean_subnet = self.addResourceCleanUp(self.client.DeleteSubnet,
                                                   SubnetId=subnet_id)
        self.get_subnet_waiter().wait_available(subnet_id)

        kwargs = {
            'SubnetId': subnet_id,
            'Description': data_utils.rand_name('ni')
        }
        resp, data = self.client.CreateNetworkInterface(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        ni_id = data['NetworkInterface']['NetworkInterfaceId']
        res_clean_ni = self.addResourceCleanUp(
            self.client.DeleteNetworkInterface, NetworkInterfaceId=ni_id)
        self.get_network_interface_waiter().wait_available(ni_id)

        resp, data = self.client.DeleteSubnet(SubnetId=subnet_id)
        self.assertEqual(400, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual('DependencyViolation', data['Error']['Code'])

        resp, data = self.client.DeleteNetworkInterface(
            NetworkInterfaceId=ni_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean_ni)
        self.get_network_interface_waiter().wait_delete(ni_id)

        resp, data = self.client.DeleteSubnet(SubnetId=subnet_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean_subnet)
        self.get_subnet_waiter().wait_delete(subnet_id)
예제 #14
0
    def test_volume_auto_termination_swithed_off(self):
        instance_type = CONF.aws.instance_type
        image_id = CONF.aws.image_id
        if not image_id:
            raise self.skipException('aws image_id does not provided')

        kwargs = {
            'ImageId': image_id,
            'InstanceType': instance_type,
            'MinCount': 1,
            'MaxCount': 1,
            'Placement': {'AvailabilityZone': CONF.aws.aws_zone}
        }
        resp, data = self.client.RunInstances(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        instance_id = data['Instances'][0]['InstanceId']
        clean_i = self.addResourceCleanUp(self.client.TerminateInstances,
                                          InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        kwargs = {
            'Size': 1,
            'AvailabilityZone': CONF.aws.aws_zone
        }
        resp, data = self.client.CreateVolume(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        volume_id = data['VolumeId']
        clean_v = self.addResourceCleanUp(self.client.DeleteVolume,
                                          VolumeId=volume_id)
        self.get_volume_waiter().wait_available(volume_id)

        kwargs = {
            'Device': '/dev/sdh',
            'InstanceId': instance_id,
            'VolumeId': volume_id,
        }
        resp, data = self.client.AttachVolume(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.addResourceCleanUp(self.client.DetachVolume, VolumeId=volume_id)
        self.get_volume_attachment_waiter().wait_available(
            volume_id, final_set=('attached'))

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(clean_i)
        self.get_instance_waiter().wait_delete(instance_id)

        resp, data = self.client.DescribeVolumes(VolumeIds=[volume_id])
        self.assertEqual(200, resp.status_code)
        self.assertEqual(1, len(data['Volumes']))
        volume = data['Volumes'][0]
        self.assertEqual('available', volume['State'])
        if 'Attachments' in volume:
            self.assertEqual(0, len(volume['Attachments']))

        resp, data = self.client.DeleteVolume(VolumeId=volume_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(clean_v)
        self.get_volume_waiter().wait_delete(volume_id)
예제 #15
0
    def test_launch_ebs_instance_with_creating_blank_volume(self):
        """Launch instance with creating blank volume."""
        device_name_prefix = _get_device_name_prefix(self.root_device_name)
        device_name = device_name_prefix + 'd'

        instance_type = CONF.aws.instance_type
        resp, data = self.client.RunInstances(
            ImageId=self.image_id, InstanceType=instance_type,
            Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1,
            BlockDeviceMappings=[{'DeviceName': device_name,
                                  'Ebs': {'VolumeSize': 1}}])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.TerminateInstances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        bdt = self.get_instance_bdm(instance_id, device_name)
        self.assertIsNotNone(bdt)
        volume_id = bdt['Ebs'].get('VolumeId')
        self.assertIsNotNone(volume_id)
        self.assertTrue(bdt['Ebs']['DeleteOnTermination'])

        resp, data = self.client.DescribeVolumes(VolumeIds=[volume_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(1, len(data['Volumes']))
        volume = data['Volumes'][0]
        self.assertEqual(1, volume['Size'])

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
예제 #16
0
    def test_describe_volume_status(self):
        kwargs = {
            'Size': 1,
            'AvailabilityZone': CONF.aws.aws_zone
        }
        resp, data = self.client.CreateVolume(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        volume_id = data['VolumeId']
        res_clean = self.addResourceCleanUp(self.client.DeleteVolume,
                                            VolumeId=volume_id)

        self.get_volume_waiter().wait_available(volume_id)

        resp, data = self.client.DescribeVolumeStatus(VolumeIds=[volume_id])
        self.assertEqual(200, resp.status_code)
        self.assertEqual(1, len(data['VolumeStatuses']))

        volume_status = data['VolumeStatuses'][0]
        self.assertIn('Actions', volume_status)
        self.assertIn('Events', volume_status)
        self.assertIn('VolumeStatus', volume_status)

        resp, data = self.client.DeleteVolume(VolumeId=volume_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_volume_waiter().wait_delete(volume_id)
예제 #17
0
    def test_create_delete_volume(self):
        kwargs = {
            'Size': 1,
            'AvailabilityZone': CONF.aws.aws_zone
        }
        resp, data = self.client.CreateVolume(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        volume_id = data['VolumeId']
        res_clean = self.addResourceCleanUp(self.client.DeleteVolume,
                                            VolumeId=volume_id)

        self.get_volume_waiter().wait_available(volume_id)

        if CONF.aws.run_incompatible_tests:
            self.assertEqual('standard', data['VolumeType'])
        self.assertEqual(1, data['Size'])
        if 'Encrypted' in data:
            self.assertFalse(data['Encrypted'])
        if 'SnapshotId' in data:
            self.assertIsNone(data['SnapshotId'])
        self.assertIsNotNone(data['CreateTime'])
        self.assertEqual(CONF.aws.aws_zone, data['AvailabilityZone'])

        resp, data = self.client.DeleteVolume(VolumeId=volume_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_volume_waiter().wait_delete(volume_id)

        resp, data = self.client.DescribeVolumes(VolumeIds=[volume_id])
        self.assertEqual(400, resp.status_code)
        self.assertEqual('InvalidVolume.NotFound', data['Error']['Code'])

        resp, data = self.client.DeleteVolume(VolumeId=volume_id)
        self.assertEqual(400, resp.status_code)
        self.assertEqual('InvalidVolume.NotFound', data['Error']['Code'])
예제 #18
0
 def cleanup_networks(self, tenant_id, client):
     LOG.info("Cleanup networks")
     networks = self.context["tenants"][tenant_id].get("networks", [])
     for network in networks:
         vpc_id = network.get("vpc_id")
         gw_id = network.get("gw_id")
         if gw_id:
             resp, data = client.DetachInternetGateway(
                 VpcId=vpc_id, InternetGatewayId=gw_id)
             if resp.status_code != 200:
                 LOG.warning(ec2_tests_base.EC2ErrorConverter(data))
             time.sleep(1)
             resp, data = client.DeleteInternetGateway(
                 InternetGatewayId=gw_id)
             if resp.status_code != 200:
                 LOG.warning(ec2_tests_base.EC2ErrorConverter(data))
             time.sleep(1)
         ni_ids = network.get("ni_ids")
         if ni_ids:
             for ni_id in ni_ids:
                 resp, data = client.DeleteNetworkInterface(
                     NetworkInterfaceId=ni_id)
                 if resp.status_code != 200:
                     LOG.warning(ec2_tests_base.EC2ErrorConverter(data))
             time.sleep(1)
         subnet_id = network.get("subnet_id")
         if subnet_id:
             resp, data = client.DeleteSubnet(SubnetId=subnet_id)
             if resp.status_code != 200:
                 LOG.warning(ec2_tests_base.EC2ErrorConverter(data))
             time.sleep(1)
         if vpc_id:
             resp, data = client.DeleteVpc(VpcId=vpc_id)
             if resp.status_code != 200:
                 LOG.warning(ec2_tests_base.EC2ErrorConverter(data))
예제 #19
0
    def create_standard_security_group(self):
        name = data_utils.rand_name('sgName')
        desc = data_utils.rand_name('sgDesc')
        kwargs = {'GroupName': name, 'Description': desc}
        resp, data = self.client.CreateSecurityGroup(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.addResourceCleanUp(self.client.DeleteSecurityGroup,
                                GroupName=name)
        time.sleep(2)

        kwargs = {
            'GroupName':
            name,
            'IpPermissions': [{
                'IpProtocol': 'icmp',
                'FromPort': -1,
                'ToPort': -1,
                'IpRanges': [{
                    'CidrIp': '0.0.0.0/0'
                }],
            }, {
                'IpProtocol': 'tcp',
                'FromPort': 22,
                'ToPort': 22,
                'IpRanges': [{
                    'CidrIp': '0.0.0.0/0'
                }],
            }]
        }
        resp, data = self.client.AuthorizeSecurityGroupIngress(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        return name
예제 #20
0
    def assign_floating_ip(self, tenant_id, client, instance_id):
        is_vpc = self.config.get("run_in_vpc", False)

        kwargs = dict()
        if is_vpc:
            kwargs['Domain'] = 'vpc'
        resp, data = client.AllocateAddress(*[], **kwargs)
        if resp.status_code != 200:
            LOG.warning(ec2_tests_base.EC2ErrorConverter(data))
            return
        alloc_id = data.get('AllocationId')
        public_ip = data['PublicIp']
        if is_vpc:
            self.context["tenants"][tenant_id]["addresses"].append(
                {'AllocationId': alloc_id})
        else:
            self.context["tenants"][tenant_id]["addresses"].append(
                {'PublicIp': public_ip})

        kwargs = {'InstanceId': instance_id}
        if is_vpc:
            kwargs['AllocationId'] = alloc_id
        else:
            kwargs['PublicIp'] = public_ip
        resp, data = client.AssociateAddress(*[], **kwargs)
        if resp.status_code != 200:
            LOG.error(ec2_tests_base.EC2ErrorConverter(data))
            if is_vpc:
                resp, data = client.ReleaseAddress(AllocationId=alloc_id)
            else:
                resp, data = client.ReleaseAddress(PublicIp=public_ip)
            if resp.status_code != 200:
                LOG.error(ec2_tests_base.EC2ErrorConverter(data))
예제 #21
0
    def terminate_instances_and_wait(self, tenant_id, client):
        ids = self.context["tenants"][tenant_id].get("servers", [])
        servers_per_run = self.config["servers_per_run"]
        mod = len(ids) / servers_per_run
        for i in xrange(0, mod):
            part_ids = ids[i * servers_per_run:(i + 1) * servers_per_run]
            resp, data = client.TerminateInstances(InstanceIds=part_ids)
            if resp.status_code != 200:
                LOG.warning(ec2_tests_base.EC2ErrorConverter(data))
        part_ids = ids[mod * servers_per_run:]
        if part_ids:
            resp, data = client.TerminateInstances(InstanceIds=part_ids)
            if resp.status_code != 200:
                LOG.warning(ec2_tests_base.EC2ErrorConverter(data))

        start_time = time.time()
        while True:
            resp, data = client.DescribeInstances(InstanceIds=ids)
            if (resp.status_code == 400 or len(data['Reservations']) == 0
                    or len(data['Reservations'][0]['Instances']) == 0):
                break
            for instance in data['Reservations'][0]['Instances']:
                assert 'error' != instance['State']['Name']
                if instance['State']['Name'] != 'terminated':
                    break
            else:
                break
            time.sleep(5)
            dtime = time.time() - start_time
            assert dtime <= self.config["build_timeout"]
    def test_delete_volume_with_snapshots(self):
        kwargs = {
            'Size': 1,
            'AvailabilityZone': CONF.aws.aws_zone
        }
        resp, data = self.client.CreateVolume(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        volume_id = data['VolumeId']
        clean_vol = self.addResourceCleanUp(self.client.DeleteVolume,
                                            VolumeId=volume_id)
        self.get_volume_waiter().wait_available(volume_id)

        desc = 'test snapshot'
        kwargs = {
            'VolumeId': volume_id,
            'Description': desc
        }
        resp, data = self.client.CreateSnapshot(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        snapshot_id = data['SnapshotId']
        res_clean = self.addResourceCleanUp(self.client.DeleteSnapshot,
                                            SnapshotId=snapshot_id)
        self.get_snapshot_waiter().wait_available(snapshot_id,
                                                  final_set=('completed'))

        resp, data = self.client.DeleteVolume(VolumeId=volume_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(clean_vol)
        self.get_volume_waiter().wait_delete(volume_id)

        resp, data = self.client.DeleteSnapshot(SnapshotId=snapshot_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_snapshot_waiter().wait_delete(snapshot_id)
예제 #23
0
    def test_create_delete_instance(self):
        instance_type = CONF.aws.instance_type
        image_id = CONF.aws.image_id
        resp, data = self.client.RunInstances(
            ImageId=image_id,
            InstanceType=instance_type,
            Placement={'AvailabilityZone': self.zone},
            MinCount=1,
            MaxCount=1)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.TerminateInstances,
                                            InstanceIds=[instance_id])
        self.assertEqual(1, len(data['Instances']))
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        resp, data = self.client.DescribeInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        reservations = data.get('Reservations', [])
        self.assertNotEmpty(reservations)
        instances = reservations[0].get('Instances', [])
        self.assertEqual(1, len(instances))

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
예제 #24
0
    def test_public_ip_is_assigned(self):
        """Is public IP assigned to launched instnace?"""
        instance_type = CONF.aws.instance_type
        image_id = CONF.aws.image_id
        resp, data = self.client.RunInstances(
            ImageId=image_id,
            InstanceType=instance_type,
            Placement={'AvailabilityZone': self.zone},
            MinCount=1,
            MaxCount=1)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(1, len(data['Instances']))
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.TerminateInstances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        instance = self.get_instance(instance_id)
        self.assertIsNotNone(instance.get('PublicIpAddress'))
        self.assertIsNotNone(instance.get('PrivateIpAddress'))
        self.assertNotEqual(instance.get('PublicIpAddress'),
                            instance.get('PrivateIpAddress'))

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
예제 #25
0
    def test_stop_instance(self):
        instance_type = CONF.aws.instance_type
        image_id = CONF.aws.image_id
        resp, data = self.client.RunInstances(
            ImageId=image_id,
            InstanceType=instance_type,
            Placement={'AvailabilityZone': self.zone},
            MinCount=1,
            MaxCount=1)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.TerminateInstances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        resp, data = self.client.StopInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        if CONF.aws.run_incompatible_tests:
            instances = data['StoppingInstances']
            self.assertEqual(1, len(instances))
            instance = instances[0]
            self.assertEqual(instance_id, instance['InstanceId'])
            self.assertEqual('running', instance['PreviousState']['Name'])
            self.assertEqual('stopping', instance['CurrentState']['Name'])

        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('stopped'))

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
예제 #26
0
    def test_get_password_data_and_console_output(self):
        instance_type = CONF.aws.instance_type
        image_id = CONF.aws.image_id
        resp, data = self.client.RunInstances(
            ImageId=image_id,
            InstanceType=instance_type,
            Placement={'AvailabilityZone': self.zone},
            MinCount=1,
            MaxCount=1)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.TerminateInstances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        resp, data = self.client.GetPasswordData(InstanceId=instance_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(instance_id, data['InstanceId'])
        self.assertIsNotNone(data['Timestamp'])
        self.assertIn('PasswordData', data)

        waiter = base.EC2Waiter(self.client.GetConsoleOutput)
        waiter.wait_no_exception(InstanceId=instance_id)

        resp, data = self.client.GetConsoleOutput(InstanceId=instance_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.assertEqual(instance_id, data['InstanceId'])
        self.assertIsNotNone(data['Timestamp'])
        self.assertIn('Output', data)

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)
    def test_create_delete_dhcp_options(self):
        kwargs = {
            'DhcpConfigurations': [
                {
                    'Key': 'domain-name',
                    'Values': ['my.com', 'it.com']
                },
                {
                    'Key': 'domain-name-servers',
                    'Values': ['8.8.8.8', '8.8.4.4']
                },
                {
                    'Key': 'ntp-servers',
                    'Values': ['1.2.3.4']
                },
                {
                    'Key': 'netbios-name-servers',
                    'Values': ['4.3.2.1']
                },
                {
                    'Key': 'netbios-node-type',
                    'Values': ['2']
                },
            ],
        }
        resp, data = self.client.CreateDhcpOptions(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        options = data['DhcpOptions']
        id = options['DhcpOptionsId']
        res_clean = self.addResourceCleanUp(self.client.DeleteDhcpOptions,
                                            DhcpOptionsId=id)
        self.assertEqual(5, len(options['DhcpConfigurations']))
        for cfg in options['DhcpConfigurations']:
            self.assertEqual(2, len(cfg))
            if cfg['Key'] == 'domain-name':
                self.assertEqual(2, len(cfg['Values']))
                values = [i['Value'] for i in cfg['Values']]
                self.assertIn('my.com', values)
                self.assertIn('it.com', values)
            elif cfg['Key'] == 'domain-name-servers':
                self.assertEqual(2, len(cfg['Values']))
                values = [i['Value'] for i in cfg['Values']]
                self.assertIn('8.8.8.8', values)
                self.assertIn('8.8.4.4', values)
            elif cfg['Key'] == 'ntp-servers':
                self.assertEqual(1, len(cfg['Values']))
                self.assertEqual('1.2.3.4', cfg['Values'][0]['Value'])
            elif cfg['Key'] == 'netbios-name-servers':
                self.assertEqual(1, len(cfg['Values']))
                self.assertEqual('4.3.2.1', cfg['Values'][0]['Value'])
            elif cfg['Key'] == 'netbios-node-type':
                self.assertEqual(1, len(cfg['Values']))
                self.assertEqual('2', cfg['Values'][0]['Value'])
            else:
                self.fail('Unknown key name in result - %s' % cfg['Key'])

        resp, data = self.client.DeleteDhcpOptions(DhcpOptionsId=id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
예제 #28
0
    def test_network_interfaces_are_deleted_on_termination(self):
        instance_type = CONF.aws.instance_type
        image_id = CONF.aws.image_id
        if not image_id:
            raise self.skipException('aws image_id does not provided')

        resp, data = self.client.RunInstances(ImageId=image_id,
                                              InstanceType=instance_type,
                                              MinCount=1,
                                              MaxCount=1,
                                              SubnetId=self.subnet_id)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        instance_id = data['Instances'][0]['InstanceId']
        res_clean = self.addResourceCleanUp(self.client.TerminateInstances,
                                            InstanceIds=[instance_id])
        self.get_instance_waiter().wait_available(instance_id,
                                                  final_set=('running'))

        instance = self.get_instance(instance_id)
        nis = instance.get('NetworkInterfaces', [])
        self.assertEqual(1, len(nis))
        self.assertTrue(nis[0]['Attachment']['DeleteOnTermination'])
        ni_id = nis[0]['NetworkInterfaceId']

        kwargs = {
            'SubnetId': self.subnet_id,
        }
        resp, data = self.client.CreateNetworkInterface(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        ni_id2 = data['NetworkInterface']['NetworkInterfaceId']
        self.addResourceCleanUp(self.client.DeleteNetworkInterface,
                                NetworkInterfaceId=ni_id2)
        self.get_network_interface_waiter().wait_available(ni_id2)
        kwargs = {
            'DeviceIndex': 2,
            'InstanceId': instance_id,
            'NetworkInterfaceId': ni_id2
        }
        resp, data = self.client.AttachNetworkInterface(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        attachment_id = data['AttachmentId']

        kwargs = {
            'NetworkInterfaceId': ni_id2,
            'Attachment': {
                'AttachmentId': attachment_id,
                'DeleteOnTermination': True,
            }
        }
        resp, data = self.client.ModifyNetworkInterfaceAttribute(*[], **kwargs)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))

        resp, data = self.client.TerminateInstances(InstanceIds=[instance_id])
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)
        self.get_instance_waiter().wait_delete(instance_id)

        self.get_network_interface_waiter().wait_delete(ni_id)
        self.get_network_interface_waiter().wait_delete(ni_id2)
 def _modify_description(**kwargs):
     resp, data = self.client.ModifyImageAttribute(ImageId=image_id,
                                                   **kwargs)
     self.assertEqual(200, resp.status_code,
                      base.EC2ErrorConverter(data))
     resp, data = self.client.DescribeImageAttribute(
         ImageId=image_id, Attribute='description')
     self.assertEqual(200, resp.status_code,
                      base.EC2ErrorConverter(data))
     self.assertEqual(new_desc, data['Description']['Value'])
예제 #30
0
    def test_create_delete_standard_address(self):
        resp, data = self.client.AllocateAddress()
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        ip = data['PublicIp']
        res_clean = self.addResourceCleanUp(self.client.ReleaseAddress,
                                            PublicIp=ip)

        resp, data = self.client.ReleaseAddress(PublicIp=ip)
        self.assertEqual(200, resp.status_code, base.EC2ErrorConverter(data))
        self.cancelResourceCleanUp(res_clean)