@pytest.mark.regions(['ap-southeast-1'])
@pytest.mark.instances(['c5.xlarge'])
@pytest.mark.oss(['alinux2'])
@pytest.mark.schedulers(['slurm', 'awsbatch'])
@pytest.mark.usefixtures('region', 'instance')
def test_tag_propagation(pcluster_config_reader, clusters_factory, scheduler, os):
    "\n    Verify tags from various sources are propagated to the expected resources.\n\n    The following resources are checked for tags:\n    - main CFN stack\n    - head node\n    - head node's root EBS volume\n    - compute node (traditional schedulers)\n    - compute node's root EBS volume (traditional schedulers)\n    - shared EBS volume\n    "
    config_file_tags = {'ConfigFileTag': 'ConfigFileTagValue'}
    version_tags = {'parallelcluster:version': get_pcluster_version()}
    cluster_config = pcluster_config_reader()
    cluster = clusters_factory(cluster_config)
    cluster_name_tags = {'parallelcluster:cluster-name': cluster.name}
    test_cases = [{'resource': 'Main CloudFormation Stack', 'tag_getter': get_main_stack_tags, 'expected_tags': (version_tags, config_file_tags)}, {'resource': 'Head Node', 'tag_getter': get_head_node_tags, 'expected_tags': (cluster_name_tags, {'Name': 'HeadNode', 'parallelcluster:node-type': 'HeadNode'})}, {'resource': 'Head Node Root Volume', 'tag_getter': get_head_node_root_volume_tags, 'expected_tags': (cluster_name_tags, {'parallelcluster:node-type': 'HeadNode'}), 'tag_getter_kwargs': {'cluster': cluster, 'os': os}}, {'resource': 'Compute Node', 'tag_getter': get_compute_node_tags, 'expected_tags': (cluster_name_tags, {'Name': 'Compute', 'parallelcluster:node-type': 'Compute'}, config_file_tags), 'skip': (scheduler == 'awsbatch')}, {'resource': 'Compute Node Root Volume', 'tag_getter': get_compute_node_root_volume_tags, 'expected_tags': (cluster_name_tags, {'parallelcluster:node-type': 'Compute'}, (config_file_tags if (scheduler == 'slurm') else {})), 'tag_getter_kwargs': {'cluster': cluster, 'os': os}, 'skip': (scheduler == 'awsbatch')}, {'resource': 'Shared EBS Volume', 'tag_getter': get_shared_volume_tags, 'expected_tags': (version_tags, config_file_tags)}]
    for test_case in test_cases:
        if test_case.get('skip'):
            continue
        logging.info('Verifying tags were propagated to %s', test_case.get('resource'))
        tag_getter = test_case.get('tag_getter')
        tag_getter_args = test_case.get('tag_getter_kwargs', {'cluster': cluster})
        observed_tags = tag_getter(**tag_getter_args)
        expected_tags = test_case['expected_tags']
        assert_that(observed_tags).contains(*convert_tags_dicts_to_tags_list(expected_tags))
Verify tags from various sources are propagated to the expected resources.

The following resources are checked for tags:
- main CFN stack
- head node
- head node's root EBS volume
- compute node (traditional schedulers)
- compute node's root EBS volume (traditional schedulers)
- shared EBS volume
@pytest.mark.regions(['ap-southeast-1'])
@pytest.mark.instances(['c5.xlarge'])
@pytest.mark.oss(['alinux2'])
@pytest.mark.schedulers(['slurm', 'awsbatch'])
@pytest.mark.usefixtures('region', 'instance')
def test_tag_propagation(pcluster_config_reader, clusters_factory, scheduler, os):
    "\n    Verify tags from various sources are propagated to the expected resources.\n\n    The following resources are checked for tags:\n    - main CFN stack\n    - head node\n    - head node's root EBS volume\n    - compute node (traditional schedulers)\n    - compute node's root EBS volume (traditional schedulers)\n    - shared EBS volume\n    "
    config_file_tags = {'ConfigFileTag': 'ConfigFileTagValue'}
    version_tags = {'parallelcluster:version': get_pcluster_version()}
    cluster_config = pcluster_config_reader()
    cluster = clusters_factory(cluster_config)
    cluster_name_tags = {'parallelcluster:cluster-name': cluster.name}
    test_cases = [{'resource': 'Main CloudFormation Stack', 'tag_getter': get_main_stack_tags, 'expected_tags': (version_tags, config_file_tags)}, {'resource': 'Head Node', 'tag_getter': get_head_node_tags, 'expected_tags': (cluster_name_tags, {'Name': 'HeadNode', 'parallelcluster:node-type': 'HeadNode'})}, {'resource': 'Head Node Root Volume', 'tag_getter': get_head_node_root_volume_tags, 'expected_tags': (cluster_name_tags, {'parallelcluster:node-type': 'HeadNode'}), 'tag_getter_kwargs': {'cluster': cluster, 'os': os}}, {'resource': 'Compute Node', 'tag_getter': get_compute_node_tags, 'expected_tags': (cluster_name_tags, {'Name': 'Compute', 'parallelcluster:node-type': 'Compute'}, config_file_tags), 'skip': (scheduler == 'awsbatch')}, {'resource': 'Compute Node Root Volume', 'tag_getter': get_compute_node_root_volume_tags, 'expected_tags': (cluster_name_tags, {'parallelcluster:node-type': 'Compute'}, (config_file_tags if (scheduler == 'slurm') else {})), 'tag_getter_kwargs': {'cluster': cluster, 'os': os}, 'skip': (scheduler == 'awsbatch')}, {'resource': 'Shared EBS Volume', 'tag_getter': get_shared_volume_tags, 'expected_tags': (version_tags, config_file_tags)}]
    for test_case in test_cases:
        if test_case.get('skip'):
            continue
        logging.info('Verifying tags were propagated to %s', test_case.get('resource'))
        tag_getter = test_case.get('tag_getter')
        tag_getter_args = test_case.get('tag_getter_kwargs', {'cluster': cluster})
        observed_tags = tag_getter(**tag_getter_args)
        expected_tags = test_case['expected_tags']
        assert_that(observed_tags).contains(*convert_tags_dicts_to_tags_list(expected_tags))