mirror of
https://github.com/ansible/awx.git
synced 2026-05-17 06:17:36 -02:30
Back to green
This commit is contained in:
@@ -35,8 +35,8 @@ def gce(cred, env, private_data_dir):
|
|||||||
json.dump(json_cred, f, indent=2)
|
json.dump(json_cred, f, indent=2)
|
||||||
f.close()
|
f.close()
|
||||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
|
||||||
env['GCE_CREDENTIALS_FILE_PATH'] = path
|
env['GCE_CREDENTIALS_FILE_PATH'] = os.path.join('/runner', os.path.basename(path))
|
||||||
env['GCP_SERVICE_ACCOUNT_FILE'] = path
|
env['GCP_SERVICE_ACCOUNT_FILE'] = os.path.join('/runner', os.path.basename(path))
|
||||||
|
|
||||||
# Handle env variables for new module types.
|
# Handle env variables for new module types.
|
||||||
# This includes gcp_compute inventory plugin and
|
# This includes gcp_compute inventory plugin and
|
||||||
|
|||||||
@@ -1544,7 +1544,7 @@ class openstack(PluginFileInjector):
|
|||||||
env = super(openstack, self).get_plugin_env(inventory_update, private_data_dir, private_data_files)
|
env = super(openstack, self).get_plugin_env(inventory_update, private_data_dir, private_data_files)
|
||||||
credential = inventory_update.get_cloud_credential()
|
credential = inventory_update.get_cloud_credential()
|
||||||
cred_data = private_data_files['credentials']
|
cred_data = private_data_files['credentials']
|
||||||
env['OS_CLIENT_CONFIG_FILE'] = cred_data[credential]
|
env['OS_CLIENT_CONFIG_FILE'] = os.path.join('/runner', os.path.basename(cred_data[credential]))
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1102,6 +1102,9 @@ class BaseTask(object):
|
|||||||
# Also set environment variables configured in AWX_TASK_ENV setting.
|
# Also set environment variables configured in AWX_TASK_ENV setting.
|
||||||
for key, value in settings.AWX_TASK_ENV.items():
|
for key, value in settings.AWX_TASK_ENV.items():
|
||||||
env[key] = str(value)
|
env[key] = str(value)
|
||||||
|
|
||||||
|
env['AWX_PRIVATE_DATA_DIR'] = private_data_dir
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
def should_use_resource_profiling(self, job):
|
def should_use_resource_profiling(self, job):
|
||||||
|
|||||||
@@ -110,7 +110,8 @@ def read_content(private_data_dir, raw_env, inventory_update):
|
|||||||
continue # Ansible runner
|
continue # Ansible runner
|
||||||
abs_file_path = os.path.join(private_data_dir, filename)
|
abs_file_path = os.path.join(private_data_dir, filename)
|
||||||
file_aliases[abs_file_path] = filename
|
file_aliases[abs_file_path] = filename
|
||||||
if abs_file_path in inverse_env:
|
runner_path = os.path.join('/runner', os.path.basename(abs_file_path))
|
||||||
|
if runner_path in inverse_env:
|
||||||
referenced_paths.add(abs_file_path)
|
referenced_paths.add(abs_file_path)
|
||||||
alias = 'file_reference'
|
alias = 'file_reference'
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
@@ -121,7 +122,7 @@ def read_content(private_data_dir, raw_env, inventory_update):
|
|||||||
raise RuntimeError('Test not able to cope with >10 references by env vars. '
|
raise RuntimeError('Test not able to cope with >10 references by env vars. '
|
||||||
'Something probably went very wrong.')
|
'Something probably went very wrong.')
|
||||||
file_aliases[abs_file_path] = alias
|
file_aliases[abs_file_path] = alias
|
||||||
for env_key in inverse_env[abs_file_path]:
|
for env_key in inverse_env[runner_path]:
|
||||||
env[env_key] = '{{{{ {} }}}}'.format(alias)
|
env[env_key] = '{{{{ {} }}}}'.format(alias)
|
||||||
try:
|
try:
|
||||||
with open(abs_file_path, 'r') as f:
|
with open(abs_file_path, 'r') as f:
|
||||||
|
|||||||
@@ -347,11 +347,12 @@ def pytest_generate_tests(metafunc):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_extra_vars(args):
|
def parse_extra_vars(args, private_data_dir):
|
||||||
extra_vars = {}
|
extra_vars = {}
|
||||||
for chunk in args:
|
for chunk in args:
|
||||||
if chunk.startswith('@/tmp/'):
|
if chunk.startswith('@/runner/'):
|
||||||
with open(chunk.strip('@'), 'r') as f:
|
local_path = os.path.join(private_data_dir, os.path.basename(chunk.strip('@')))
|
||||||
|
with open(local_path, 'r') as f:
|
||||||
extra_vars.update(yaml.load(f, Loader=SafeLoader))
|
extra_vars.update(yaml.load(f, Loader=SafeLoader))
|
||||||
return extra_vars
|
return extra_vars
|
||||||
|
|
||||||
@@ -597,7 +598,7 @@ class TestGenericRun():
|
|||||||
assert resource_profiling_params['resource_profiling_cpu_poll_interval'] == '0.25'
|
assert resource_profiling_params['resource_profiling_cpu_poll_interval'] == '0.25'
|
||||||
assert resource_profiling_params['resource_profiling_memory_poll_interval'] == '0.25'
|
assert resource_profiling_params['resource_profiling_memory_poll_interval'] == '0.25'
|
||||||
assert resource_profiling_params['resource_profiling_pid_poll_interval'] == '0.25'
|
assert resource_profiling_params['resource_profiling_pid_poll_interval'] == '0.25'
|
||||||
assert resource_profiling_params['resource_profiling_results_dir'] == '/fake_private_data_dir/artifacts/playbook_profiling'
|
assert resource_profiling_params['resource_profiling_results_dir'] == '/runner/artifacts/playbook_profiling'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("scenario, profiling_enabled", [
|
@pytest.mark.parametrize("scenario, profiling_enabled", [
|
||||||
@@ -656,30 +657,6 @@ class TestGenericRun():
|
|||||||
env = task.build_env(job, private_data_dir)
|
env = task.build_env(job, private_data_dir)
|
||||||
assert env['FOO'] == 'BAR'
|
assert env['FOO'] == 'BAR'
|
||||||
|
|
||||||
def test_valid_custom_virtualenv(self, patch_Job, private_data_dir):
|
|
||||||
job = Job(project=Project(), inventory=Inventory())
|
|
||||||
|
|
||||||
with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as tempdir:
|
|
||||||
job.project.custom_virtualenv = tempdir
|
|
||||||
os.makedirs(os.path.join(tempdir, 'lib'))
|
|
||||||
os.makedirs(os.path.join(tempdir, 'bin', 'activate'))
|
|
||||||
|
|
||||||
task = tasks.RunJob()
|
|
||||||
env = task.build_env(job, private_data_dir)
|
|
||||||
|
|
||||||
assert env['PATH'].startswith(os.path.join(tempdir, 'bin'))
|
|
||||||
assert env['VIRTUAL_ENV'] == tempdir
|
|
||||||
|
|
||||||
def test_invalid_custom_virtualenv(self, patch_Job, private_data_dir):
|
|
||||||
job = Job(project=Project(), inventory=Inventory())
|
|
||||||
job.project.custom_virtualenv = '/var/lib/awx/venv/missing'
|
|
||||||
task = tasks.RunJob()
|
|
||||||
|
|
||||||
with pytest.raises(tasks.InvalidVirtualenvError) as e:
|
|
||||||
task.build_env(job, private_data_dir)
|
|
||||||
|
|
||||||
assert 'Invalid virtual environment selected: /var/lib/awx/venv/missing' == str(e.value)
|
|
||||||
|
|
||||||
|
|
||||||
class TestAdhocRun(TestJobExecution):
|
class TestAdhocRun(TestJobExecution):
|
||||||
|
|
||||||
@@ -1203,7 +1180,9 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
credential.credential_type.inject_credential(
|
credential.credential_type.inject_credential(
|
||||||
credential, env, safe_env, [], private_data_dir
|
credential, env, safe_env, [], private_data_dir
|
||||||
)
|
)
|
||||||
json_data = json.load(open(env['GCE_CREDENTIALS_FILE_PATH'], 'rb'))
|
runner_path = env['GCE_CREDENTIALS_FILE_PATH']
|
||||||
|
local_path = os.path.join(private_data_dir, os.path.basename(runner_path))
|
||||||
|
json_data = json.load(open(local_path, 'rb'))
|
||||||
assert json_data['type'] == 'service_account'
|
assert json_data['type'] == 'service_account'
|
||||||
assert json_data['private_key'] == self.EXAMPLE_PRIVATE_KEY
|
assert json_data['private_key'] == self.EXAMPLE_PRIVATE_KEY
|
||||||
assert json_data['client_email'] == 'bob'
|
assert json_data['client_email'] == 'bob'
|
||||||
@@ -1344,7 +1323,7 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
)
|
)
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(env['OVIRT_INI_PATH'])
|
config.read(os.path.join(private_data_dir, os.path.basename(env['OVIRT_INI_PATH'])))
|
||||||
assert config.get('ovirt', 'ovirt_url') == 'some-ovirt-host.example.org'
|
assert config.get('ovirt', 'ovirt_url') == 'some-ovirt-host.example.org'
|
||||||
assert config.get('ovirt', 'ovirt_username') == 'bob'
|
assert config.get('ovirt', 'ovirt_username') == 'bob'
|
||||||
assert config.get('ovirt', 'ovirt_password') == 'some-pass'
|
assert config.get('ovirt', 'ovirt_password') == 'some-pass'
|
||||||
@@ -1577,7 +1556,7 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
credential.credential_type.inject_credential(
|
credential.credential_type.inject_credential(
|
||||||
credential, {}, {}, args, private_data_dir
|
credential, {}, {}, args, private_data_dir
|
||||||
)
|
)
|
||||||
extra_vars = parse_extra_vars(args)
|
extra_vars = parse_extra_vars(args, private_data_dir)
|
||||||
|
|
||||||
assert extra_vars["api_token"] == "ABC123"
|
assert extra_vars["api_token"] == "ABC123"
|
||||||
assert hasattr(extra_vars["api_token"], '__UNSAFE__')
|
assert hasattr(extra_vars["api_token"], '__UNSAFE__')
|
||||||
@@ -1612,7 +1591,7 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
credential.credential_type.inject_credential(
|
credential.credential_type.inject_credential(
|
||||||
credential, {}, {}, args, private_data_dir
|
credential, {}, {}, args, private_data_dir
|
||||||
)
|
)
|
||||||
extra_vars = parse_extra_vars(args)
|
extra_vars = parse_extra_vars(args, private_data_dir)
|
||||||
|
|
||||||
assert extra_vars["turbo_button"] == "True"
|
assert extra_vars["turbo_button"] == "True"
|
||||||
return ['successful', 0]
|
return ['successful', 0]
|
||||||
@@ -1647,7 +1626,7 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
credential.credential_type.inject_credential(
|
credential.credential_type.inject_credential(
|
||||||
credential, {}, {}, args, private_data_dir
|
credential, {}, {}, args, private_data_dir
|
||||||
)
|
)
|
||||||
extra_vars = parse_extra_vars(args)
|
extra_vars = parse_extra_vars(args, private_data_dir)
|
||||||
|
|
||||||
assert extra_vars["turbo_button"] == "FAST!"
|
assert extra_vars["turbo_button"] == "FAST!"
|
||||||
|
|
||||||
@@ -1687,7 +1666,7 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
credential, {}, {}, args, private_data_dir
|
credential, {}, {}, args, private_data_dir
|
||||||
)
|
)
|
||||||
|
|
||||||
extra_vars = parse_extra_vars(args)
|
extra_vars = parse_extra_vars(args, private_data_dir)
|
||||||
assert extra_vars["password"] == "SUPER-SECRET-123"
|
assert extra_vars["password"] == "SUPER-SECRET-123"
|
||||||
|
|
||||||
def test_custom_environment_injectors_with_file(self, private_data_dir):
|
def test_custom_environment_injectors_with_file(self, private_data_dir):
|
||||||
@@ -1722,7 +1701,8 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
credential, env, {}, [], private_data_dir
|
credential, env, {}, [], private_data_dir
|
||||||
)
|
)
|
||||||
|
|
||||||
assert open(env['MY_CLOUD_INI_FILE'], 'r').read() == '[mycloud]\nABC123'
|
path = os.path.join(private_data_dir, os.path.basename(env['MY_CLOUD_INI_FILE']))
|
||||||
|
assert open(path, 'r').read() == '[mycloud]\nABC123'
|
||||||
|
|
||||||
def test_custom_environment_injectors_with_unicode_content(self, private_data_dir):
|
def test_custom_environment_injectors_with_unicode_content(self, private_data_dir):
|
||||||
value = 'Iñtërnâtiônàlizætiøn'
|
value = 'Iñtërnâtiônàlizætiøn'
|
||||||
@@ -1746,7 +1726,8 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
credential, env, {}, [], private_data_dir
|
credential, env, {}, [], private_data_dir
|
||||||
)
|
)
|
||||||
|
|
||||||
assert open(env['MY_CLOUD_INI_FILE'], 'r').read() == value
|
path = os.path.join(private_data_dir, os.path.basename(env['MY_CLOUD_INI_FILE']))
|
||||||
|
assert open(path, 'r').read() == value
|
||||||
|
|
||||||
def test_custom_environment_injectors_with_files(self, private_data_dir):
|
def test_custom_environment_injectors_with_files(self, private_data_dir):
|
||||||
some_cloud = CredentialType(
|
some_cloud = CredentialType(
|
||||||
@@ -1786,8 +1767,10 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
credential, env, {}, [], private_data_dir
|
credential, env, {}, [], private_data_dir
|
||||||
)
|
)
|
||||||
|
|
||||||
assert open(env['MY_CERT_INI_FILE'], 'r').read() == '[mycert]\nCERT123'
|
cert_path = os.path.join(private_data_dir, os.path.basename(env['MY_CERT_INI_FILE']))
|
||||||
assert open(env['MY_KEY_INI_FILE'], 'r').read() == '[mykey]\nKEY123'
|
key_path = os.path.join(private_data_dir, os.path.basename(env['MY_KEY_INI_FILE']))
|
||||||
|
assert open(cert_path, 'r').read() == '[mycert]\nCERT123'
|
||||||
|
assert open(key_path, 'r').read() == '[mykey]\nKEY123'
|
||||||
|
|
||||||
def test_multi_cloud(self, private_data_dir):
|
def test_multi_cloud(self, private_data_dir):
|
||||||
gce = CredentialType.defaults['gce']()
|
gce = CredentialType.defaults['gce']()
|
||||||
@@ -1826,7 +1809,8 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
assert env['AZURE_AD_USER'] == 'bob'
|
assert env['AZURE_AD_USER'] == 'bob'
|
||||||
assert env['AZURE_PASSWORD'] == 'secret'
|
assert env['AZURE_PASSWORD'] == 'secret'
|
||||||
|
|
||||||
json_data = json.load(open(env['GCE_CREDENTIALS_FILE_PATH'], 'rb'))
|
path = os.path.join(private_data_dir, os.path.basename(env['GCE_CREDENTIALS_FILE_PATH']))
|
||||||
|
json_data = json.load(open(path, 'rb'))
|
||||||
assert json_data['type'] == 'service_account'
|
assert json_data['type'] == 'service_account'
|
||||||
assert json_data['private_key'] == self.EXAMPLE_PRIVATE_KEY
|
assert json_data['private_key'] == self.EXAMPLE_PRIVATE_KEY
|
||||||
assert json_data['client_email'] == 'bob'
|
assert json_data['client_email'] == 'bob'
|
||||||
@@ -2307,7 +2291,8 @@ class TestInventoryUpdateCredentials(TestJobExecution):
|
|||||||
private_data_files = task.build_private_data_files(inventory_update, private_data_dir)
|
private_data_files = task.build_private_data_files(inventory_update, private_data_dir)
|
||||||
env = task.build_env(inventory_update, private_data_dir, False, private_data_files)
|
env = task.build_env(inventory_update, private_data_dir, False, private_data_files)
|
||||||
|
|
||||||
shade_config = open(env['OS_CLIENT_CONFIG_FILE'], 'r').read()
|
path = os.path.join(private_data_dir, os.path.basename(env['OS_CLIENT_CONFIG_FILE']))
|
||||||
|
shade_config = open(path, 'r').read()
|
||||||
assert '\n'.join([
|
assert '\n'.join([
|
||||||
'clouds:',
|
'clouds:',
|
||||||
' devstack:',
|
' devstack:',
|
||||||
|
|||||||
Reference in New Issue
Block a user