def test_draw_instance_table(): objects = [ ec2_to_local_instance( ec2_instance_mock(tags={ 'openqa_var_JOB_ID': 123, 'openqa_created_by': 'openqa-suse-de' }), 'ns', 'moon-west'), ec2_to_local_instance( ec2_instance_mock( tags={ 'openqa_var_JOB_ID': 666, 'openqa_created_by': 'i-dont-have-a-link' }), 'ns', 'moon-west') ] s = draw_instance_table(objects) assert 'https://openqa.suse.de/t123' in s assert 'https://openqa.suse.de/t666' not in s for instance_id in [o.instance_id for o in objects]: assert instance_id in s
def test_ec2_to_local_instance(): test_instance = ec2_instance_mock() test_vault_namespace = fake.uuid4() test_region = fake.uuid4() result = ec2_to_local_instance(test_instance, test_vault_namespace, test_region) assert result.provider == ProviderChoice.EC2 assert result.vault_namespace == test_vault_namespace assert result.first_seen == test_instance.launch_time assert result.instance_id == test_instance.instance_id assert result.state == StateChoice.ACTIVE assert result.region == test_region json.loads(result.csp_info)
def test_ec2_to_json(): test_instance = ec2_instance_mock() test_instance.state_reason = None test_instance.image = None result = ec2_to_json(test_instance) assert result['state'] == test_instance.state['Name'] assert result['image_id'] == test_instance.image_id assert result['instance_lifecycle'] == test_instance.instance_lifecycle assert result['instance_type'] == test_instance.instance_type assert result['kernel_id'] == test_instance.kernel_id assert result['launch_time'] == test_instance.launch_time.isoformat() assert result['public_ip_address'] == test_instance.public_ip_address assert len(result['security_groups']) == len(test_instance.security_groups) # TODO compare values of 'security_groups' assert result['sriov_net_support'] == test_instance.sriov_net_support for t in test_instance.tags: assert result['tags'][t['Key']] == t['Value'] assert 'state_reason' not in result assert 'image' not in result
def test_ec2_to_json_image_with_meta(): test_instance = ec2_instance_mock() result = ec2_to_json(test_instance) assert result['image']['name'] == test_instance.image.name
def test_ec2_to_json_image_without_meta(): test_instance = ec2_instance_mock() test_instance.image.meta.data = None result = ec2_to_json(test_instance) assert result['image']['image_id'] == test_instance.image.image_id assert 'name' not in result['image']
def test_ec2_to_json_state_reason(): test_instance = ec2_instance_mock() result = ec2_to_json(test_instance) assert result['state_reason'] == test_instance.state_reason['Message']