Debian Codegraph @

test/lib/ansible_test/_internal/commands/integration/windows.py

raw
1 """Windows integration testing."""
2
3 from __future__ import annotations
4
5 import os
6
7 from ...util import (
8 ApplicationError,
9 ANSIBLE_TEST_CONFIG_ROOT,
10 )
11
12 from ...util_common import (
13 handle_layout_messages,
14 )
15
16 from ...containers import (
17 create_container_hooks,
18 local_ssh,
19 root_ssh,
20 )
21
22 from ...target import (
23 walk_windows_integration_targets,
24 )
25
26 from ...config import (
27 WindowsIntegrationConfig,
28 )
29
30 from ...host_configs import (
31 WindowsInventoryConfig,
32 WindowsRemoteConfig,
33 )
34
35 from . import (
36 command_integration_filter,
37 command_integration_filtered,
38 get_inventory_absolute_path,
39 get_inventory_relative_path,
40 check_inventory,
41 delegate_inventory,
42 )
43
44 from ...data import (
45 data_context,
46 )
47
48
49 def command_windows_integration(args: WindowsIntegrationConfig) -> None:
50 """Entry point for the `windows-integration` command."""
51 handle_layout_messages(data_context().content.integration_messages)
52
53 inventory_relative_path = get_inventory_relative_path(args)
54 template_path = os.path.join(ANSIBLE_TEST_CONFIG_ROOT, os.path.basename(inventory_relative_path)) + '.template'
55
56 if issubclass(args.target_type, WindowsInventoryConfig):
57 target = args.only_target(WindowsInventoryConfig)
58 inventory_path = get_inventory_absolute_path(args, target)
59
60 if args.delegate or not target.path:
61 target.path = inventory_relative_path
62 else:
63 inventory_path = os.path.join(data_context().content.root, inventory_relative_path)
64
65 if not args.explain and not issubclass(args.target_type, WindowsRemoteConfig) and not os.path.isfile(inventory_path):
66 raise ApplicationError(
67 'Inventory not found: %s\n'
68 'Use --inventory to specify the inventory path.\n'
69 'Use --windows to provision resources and generate an inventory file.\n'
70 'See also inventory template: %s' % (inventory_path, template_path)
71 )
72
73 check_inventory(args, inventory_path)
74 delegate_inventory(args, inventory_path)
75
76 all_targets = tuple(walk_windows_integration_targets(include_hidden=True))
77 host_state, internal_targets = command_integration_filter(args, all_targets)
78 control_connections = [local_ssh(args, host_state.controller_profile.python)]
79 managed_connections = [root_ssh(ssh) for ssh in host_state.get_controller_target_connections()]
80 pre_target, post_target = create_container_hooks(args, control_connections, managed_connections)
81
82 command_integration_filtered(args, host_state, internal_targets, all_targets, inventory_path, pre_target=pre_target, post_target=post_target)