class TestInstances(TestBase):
@retry_with_error_code(retry_num=1, always_retry=True, error_codes=['InvalidSecurityGroupId.NotFound'])
async def test_param_instance_invalid(self):
"""
使用合法和非法入参测试 RunInstances: Invalid
"""
async def clean_callback(api_resp):
"""
清理测试创建类 API 产生的资源
"""
instance = Instance(
region_id=region_id,
instance_id=api_resp['InstanceIdSets']['InstanceIdSet'][0]
)
await asyncio.sleep(60)
await instance.delete(_retry=True, wait=True)
v_switch, sg_normal, sg_enterprise, instance_type, image_id = await get_run_instance_kwargs()
if cfg.CONF.env.is_jvshita:
kwargs = {
}
else:
kwargs = dict(
deployment_set_id=ParamSchema(
valid_values=[None],
invalid_values=['Invlaid'],
error_codes='InvalidInstanceType.NotSupported'
),
)
await self._test_api(
api_=Resource(region_id=region_id, zone_id=zone_id).api_RunInstances,
test_valid=False,
clean_callback_=clean_callback,
region_id=ParamSchema(
valid_values=[region_id],
invalid_values=['Invalid'],
error_codes=lambda code: code in ('InvalidRegionId.NotFound', 'InvalidRegionId')
),
zone_id=ParamSchema(
valid_values=[zone_id],
invalid_values=['Invalid'],
error_codes='InvalidZoneId.NotFound'
),
image_id=ParamSchema(
valid_values=[image_id]
),
instance_type=ParamSchema(
valid_values=[instance_type]
),
v_switch_id=ParamSchema(
valid_values=[v_switch.v_switch_id]
),
security_group_id=ParamSchema(
valid_values=[sg_normal.security_group_id]
),
security_group_ids__1=ParamSchema(
valid_values=[None],
invalid_values=['sg-test', sg_normal.security_group_id],
error_codes='InvalidSecurityGroupId.SingleIdAndMultiIdConflict'
),
instance_name=ParamSchema(
valid_values=[BaseResource.gen_name('i-as')]
),
system_disk__size=ParamSchema(
valid_values=[40],
invalid_values=[10, 501],
error_codes=['InvalidSystemDiskSize.LessThanMinSize', lambda code: code in (
'InvalidDisk.SystemDiskSize', 'InvalidSystemDiskSize.ValueNotSupported')]
),
system_disk__category=ParamSchema(
valid_values=['cloud_efficiency'],
invalid_values=['Invalid'],
error_codes='InvalidDiskCategory.ValueNotSupported'
),
system_disk__disk_name=ParamSchema(
valid_values=['as'],
invalid_values=['a', '_as', 'a' * 129, 'http://', 'https://'],
error_codes='InvalidDiskName.Malformed'
),
system_disk__description=ParamSchema(
valid_values=['des'],
invalid_values=['a', 'a' * 257, 'http://', 'https://'],
error_codes='InvalidDescription.Malformed'
),
image_family=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='UnexpectedImageFamily.ImageIdSupplied'
),
internet_charge_type=ParamSchema(
valid_values=['PayByTraffic'],
invalid_values=['Invalid'],
error_codes='InvalidInternetChargeType.ValueNotSupported'
),
auto_renew_period=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidParameter'
),
internet_max_bandwidth_in=ParamSchema(
valid_values=[None],
invalid_values=[-1],
error_codes='InvalidInternetMaxBandwidthIn.Malformed'
),
internet_max_bandwidth_out=ParamSchema(
valid_values=[None],
invalid_values=[-1, 101],
error_codes=[lambda code: code in ('HOSTNAME_ILLEGAL', 'InvalidInternetMaxBandwidthOut.Malformed'),
'InvalidParameter.Bandwidth']
),
host_name=ParamSchema(
valid_values=[None],
invalid_values=['h'],
error_codes='InvalidHostName.Malformed'
),
password=ParamSchema(
valid_values=[None],
invalid_values=['w'],
error_codes='InvalidPassword.Malformed'
),
private_ip_address=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes=lambda code: code in ('InvalidPrivateIpAddress.Malformed', 'InvalidIp.Address')
),
io_optimized=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidIoOptimize.ValueNotSupported'
),
instance_charge_type=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidInstanceChargeType.NotFound'
),
period=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidParameter'
),
spot_strategy=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidSpotStrategy'
),
key_pair_name=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidKeyPairName.NotFound'
),
spot_price_limit=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidParameter'
),
spot_duration=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidParameter'
),
spot_interruption_behavior=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidSpotInterruptionBehavior'
),
ram_role_name=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidRamRole.NotFound'
),
resource_group_id=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidResourceGroup.NotFound'
),
hpc_cluster_id=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidHpcClusterId.Unnecessary'
),
dedicated_host_id=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidDedicatedHostId.NotFound'
),
credit_specification=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidParameter.CreditSpecification'
),
affinity=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes=lambda code: code in ('InvalidParameter.Affinity', 'UnknownError')
),
tenancy=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes=lambda code: code in ('InvalidParam.Tenancy', 'UnknownError')
),
storage_set_id=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidParameter.StorageSetPartitionNumber'
),
storage_set_partition_number=ParamSchema(
valid_values=[None],
invalid_values=['Invalid'],
error_codes='InvalidParameter'
),
**kwargs,
)