1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
"""Network integration testing."""
from __future__ import annotations
import os
from ...util import (
ApplicationError,
ANSIBLE_TEST_CONFIG_ROOT,
)
from ...util_common import (
handle_layout_messages,
)
from ...target import (
walk_network_integration_targets,
)
from ...config import (
NetworkIntegrationConfig,
)
from . import (
command_integration_filter,
command_integration_filtered,
get_inventory_absolute_path,
get_inventory_relative_path,
check_inventory,
delegate_inventory,
)
from ...data import (
data_context,
)
from ...host_configs import (
NetworkInventoryConfig,
NetworkRemoteConfig,
)
def command_network_integration(args: NetworkIntegrationConfig) -> None:
"""Entry point for the `network-integration` command."""
handle_layout_messages(data_context().content.integration_messages)
inventory_relative_path = get_inventory_relative_path(args)
template_path = os.path.join(ANSIBLE_TEST_CONFIG_ROOT, os.path.basename(inventory_relative_path)) + '.template'
if issubclass(args.target_type, NetworkInventoryConfig):
target = args.only_target(NetworkInventoryConfig)
inventory_path = get_inventory_absolute_path(args, target)
if args.delegate or not target.path:
target.path = inventory_relative_path
else:
inventory_path = os.path.join(data_context().content.root, inventory_relative_path)
if args.no_temp_workdir:
# temporary solution to keep DCI tests working
inventory_exists = os.path.exists(inventory_path)
else:
inventory_exists = os.path.isfile(inventory_path)
if not args.explain and not issubclass(args.target_type, NetworkRemoteConfig) and not inventory_exists:
raise ApplicationError(
'Inventory not found: %s\n'
'Use --inventory to specify the inventory path.\n'
'Use --platform to provision resources and generate an inventory file.\n'
'See also inventory template: %s' % (inventory_path, template_path)
)
check_inventory(args, inventory_path)
delegate_inventory(args, inventory_path)
all_targets = tuple(walk_network_integration_targets(include_hidden=True))
host_state, internal_targets = command_integration_filter(args, all_targets)
command_integration_filtered(args, host_state, internal_targets, all_targets, inventory_path)
|