mirror of
https://github.com/ansible/awx.git
synced 2026-02-16 10:40:01 -03:30
Merge pull request #3848 from AlanCoding/standard_injector
Move outlier gce cache logic to standard place Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -12,7 +12,6 @@ import os.path
|
|||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
import yaml
|
import yaml
|
||||||
import configparser
|
import configparser
|
||||||
import stat
|
|
||||||
import tempfile
|
import tempfile
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from distutils.version import LooseVersion as Version
|
from distutils.version import LooseVersion as Version
|
||||||
@@ -1964,7 +1963,7 @@ class PluginFileInjector(object):
|
|||||||
if cp.sections():
|
if cp.sections():
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
cp.write(f)
|
cp.write(f)
|
||||||
private_data = private_data = {'credentials': {}}
|
private_data = {'credentials': {}}
|
||||||
private_data['credentials'][credential] = f.getvalue()
|
private_data['credentials'][credential] = f.getvalue()
|
||||||
return private_data
|
return private_data
|
||||||
else:
|
else:
|
||||||
@@ -2324,6 +2323,7 @@ class ec2(PluginFileInjector):
|
|||||||
class gce(PluginFileInjector):
|
class gce(PluginFileInjector):
|
||||||
plugin_name = 'gcp_compute'
|
plugin_name = 'gcp_compute'
|
||||||
initial_version = '2.8' # Driven by unsafe group names issue, hostvars
|
initial_version = '2.8' # Driven by unsafe group names issue, hostvars
|
||||||
|
ini_env_reference = 'GCE_INI_PATH'
|
||||||
base_injector = 'managed'
|
base_injector = 'managed'
|
||||||
|
|
||||||
def get_script_env(self, inventory_update, private_data_dir, private_data_files):
|
def get_script_env(self, inventory_update, private_data_dir, private_data_files):
|
||||||
@@ -2335,16 +2335,6 @@ class gce(PluginFileInjector):
|
|||||||
env['GCE_EMAIL'] = cred.get_input('username', default='')
|
env['GCE_EMAIL'] = cred.get_input('username', default='')
|
||||||
env['GCE_PROJECT'] = cred.get_input('project', default='')
|
env['GCE_PROJECT'] = cred.get_input('project', default='')
|
||||||
env['GCE_ZONE'] = inventory_update.source_regions if inventory_update.source_regions != 'all' else '' # noqa
|
env['GCE_ZONE'] = inventory_update.source_regions if inventory_update.source_regions != 'all' else '' # noqa
|
||||||
|
|
||||||
# by default, the GCE inventory source caches results on disk for
|
|
||||||
# 5 minutes; disable this behavior
|
|
||||||
cp = configparser.ConfigParser()
|
|
||||||
cp.add_section('cache')
|
|
||||||
cp.set('cache', 'cache_max_age', '0')
|
|
||||||
handle, path = tempfile.mkstemp(dir=private_data_dir)
|
|
||||||
cp.write(os.fdopen(handle, 'w'))
|
|
||||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
|
|
||||||
env['GCE_INI_PATH'] = path
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
def _compat_compose_vars(self):
|
def _compat_compose_vars(self):
|
||||||
@@ -2419,6 +2409,14 @@ class gce(PluginFileInjector):
|
|||||||
ret['zones'] = inventory_update.source_regions.split(',')
|
ret['zones'] = inventory_update.source_regions.split(',')
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def build_script_private_data(self, inventory_update, private_data_dir):
|
||||||
|
cp = configparser.RawConfigParser()
|
||||||
|
# by default, the GCE inventory source caches results on disk for
|
||||||
|
# 5 minutes; disable this behavior
|
||||||
|
cp.add_section('cache')
|
||||||
|
cp.set('cache', 'cache_max_age', '0')
|
||||||
|
return self.dump_cp(cp, inventory_update.get_cloud_credential())
|
||||||
|
|
||||||
|
|
||||||
class vmware(PluginFileInjector):
|
class vmware(PluginFileInjector):
|
||||||
# plugin_name = 'vmware_vm_inventory' # FIXME: implement me
|
# plugin_name = 'vmware_vm_inventory' # FIXME: implement me
|
||||||
|
|||||||
@@ -2234,7 +2234,9 @@ class TestInventoryUpdateCredentials(TestJobExecution):
|
|||||||
inventory_update.get_extra_credentials = mocker.Mock(return_value=[])
|
inventory_update.get_extra_credentials = mocker.Mock(return_value=[])
|
||||||
settings.AWX_TASK_ENV = {'FOO': 'BAR'}
|
settings.AWX_TASK_ENV = {'FOO': 'BAR'}
|
||||||
|
|
||||||
env = task.build_env(inventory_update, private_data_dir, False)
|
with mocker.patch('awx.main.tasks._get_ansible_version', mocker.MagicMock(return_value='2.7')):
|
||||||
|
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)
|
||||||
|
|
||||||
assert env['FOO'] == 'BAR'
|
assert env['FOO'] == 'BAR'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user