mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 05:55:59 -03:30
Merge pull request #34 from ryanpetrello/release_3.2.0
more tower -> awx for task execution and isolated tooling
This commit is contained in:
@@ -193,7 +193,7 @@ class IsolatedManager(object):
|
|||||||
isolated_ssh_path = None
|
isolated_ssh_path = None
|
||||||
try:
|
try:
|
||||||
if getattr(settings, 'AWX_ISOLATED_PRIVATE_KEY', None):
|
if getattr(settings, 'AWX_ISOLATED_PRIVATE_KEY', None):
|
||||||
isolated_ssh_path = tempfile.mkdtemp(prefix='ansible_tower_isolated', dir=settings.AWX_PROOT_BASE_PATH)
|
isolated_ssh_path = tempfile.mkdtemp(prefix='ansible_awx_isolated', dir=settings.AWX_PROOT_BASE_PATH)
|
||||||
os.chmod(isolated_ssh_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
os.chmod(isolated_ssh_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
isolated_key = os.path.join(isolated_ssh_path, '.isolated')
|
isolated_key = os.path.join(isolated_ssh_path, '.isolated')
|
||||||
ssh_sock = os.path.join(isolated_ssh_path, '.isolated_ssh_auth.sock')
|
ssh_sock = os.path.join(isolated_ssh_path, '.isolated_ssh_auth.sock')
|
||||||
@@ -446,7 +446,7 @@ class IsolatedManager(object):
|
|||||||
isolated job on
|
isolated job on
|
||||||
:param private_data_dir: an absolute path on the local file system
|
:param private_data_dir: an absolute path on the local file system
|
||||||
where job-specific data should be written
|
where job-specific data should be written
|
||||||
(i.e., `/tmp/ansible_tower_xyz/`)
|
(i.e., `/tmp/ansible_awx_xyz/`)
|
||||||
:param proot_temp_dir: a temporary directory which bwrap maps
|
:param proot_temp_dir: a temporary directory which bwrap maps
|
||||||
restricted paths to
|
restricted paths to
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ def run_isolated_job(private_data_dir, secrets, logfile=sys.stdout):
|
|||||||
|
|
||||||
:param private_data_dir: an absolute path on the local file system where
|
:param private_data_dir: an absolute path on the local file system where
|
||||||
job metadata exists (i.e.,
|
job metadata exists (i.e.,
|
||||||
`/tmp/ansible_tower_xyz/`)
|
`/tmp/ansible_awx_xyz/`)
|
||||||
:param secrets: a dict containing sensitive job metadata, {
|
:param secrets: a dict containing sensitive job metadata, {
|
||||||
'env': { ... } # environment variables,
|
'env': { ... } # environment variables,
|
||||||
'passwords': { ... } # pexpect password prompts
|
'passwords': { ... } # pexpect password prompts
|
||||||
|
|||||||
@@ -472,7 +472,7 @@ class BaseTask(Task):
|
|||||||
'''
|
'''
|
||||||
Create a temporary directory for job-related files.
|
Create a temporary directory for job-related files.
|
||||||
'''
|
'''
|
||||||
path = tempfile.mkdtemp(prefix='ansible_tower_%s_' % instance.pk, dir=settings.AWX_PROOT_BASE_PATH)
|
path = tempfile.mkdtemp(prefix='ansible_awx_%s_' % instance.pk, dir=settings.AWX_PROOT_BASE_PATH)
|
||||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
self.cleanup_paths.append(path)
|
self.cleanup_paths.append(path)
|
||||||
return path
|
return path
|
||||||
@@ -1857,7 +1857,7 @@ class RunInventoryUpdate(BaseTask):
|
|||||||
elif src == 'scm':
|
elif src == 'scm':
|
||||||
args.append(inventory_update.get_actual_source_path())
|
args.append(inventory_update.get_actual_source_path())
|
||||||
elif src == 'custom':
|
elif src == 'custom':
|
||||||
runpath = tempfile.mkdtemp(prefix='ansible_tower_inventory_', dir=settings.AWX_PROOT_BASE_PATH)
|
runpath = tempfile.mkdtemp(prefix='ansible_awx_inventory_', dir=settings.AWX_PROOT_BASE_PATH)
|
||||||
handle, path = tempfile.mkstemp(dir=runpath)
|
handle, path = tempfile.mkstemp(dir=runpath)
|
||||||
f = os.fdopen(handle, 'w')
|
f = os.fdopen(handle, 'w')
|
||||||
if inventory_update.source_script is None:
|
if inventory_update.source_script is None:
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def rsa_key(request):
|
|||||||
|
|
||||||
@pytest.fixture(scope='function')
|
@pytest.fixture(scope='function')
|
||||||
def private_data_dir(request):
|
def private_data_dir(request):
|
||||||
path = tempfile.mkdtemp(prefix='ansible_tower_unit_test')
|
path = tempfile.mkdtemp(prefix='ansible_awx_unit_test')
|
||||||
request.addfinalizer(lambda: shutil.rmtree(path))
|
request.addfinalizer(lambda: shutil.rmtree(path))
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ class TestJobExecution:
|
|||||||
EXAMPLE_PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----\nxyz==\n-----END PRIVATE KEY-----'
|
EXAMPLE_PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----\nxyz==\n-----END PRIVATE KEY-----'
|
||||||
|
|
||||||
def setup_method(self, method):
|
def setup_method(self, method):
|
||||||
self.project_path = tempfile.mkdtemp(prefix='ansible_tower_project_')
|
self.project_path = tempfile.mkdtemp(prefix='ansible_awx_project_')
|
||||||
with open(os.path.join(self.project_path, 'helloworld.yml'), 'w') as f:
|
with open(os.path.join(self.project_path, 'helloworld.yml'), 'w') as f:
|
||||||
f.write('---')
|
f.write('---')
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ class TestIsolatedExecution(TestJobExecution):
|
|||||||
credential.inputs['password'] = encrypt_field(credential, 'password')
|
credential.inputs['password'] = encrypt_field(credential, 'password')
|
||||||
self.instance.credential = credential
|
self.instance.credential = credential
|
||||||
|
|
||||||
private_data = tempfile.mkdtemp(prefix='ansible_tower_')
|
private_data = tempfile.mkdtemp(prefix='ansible_awx_')
|
||||||
self.task.build_private_data_dir = mock.Mock(return_value=private_data)
|
self.task.build_private_data_dir = mock.Mock(return_value=private_data)
|
||||||
inventory = json.dumps({"all": {"hosts": ["localhost"]}})
|
inventory = json.dumps({"all": {"hosts": ["localhost"]}})
|
||||||
|
|
||||||
@@ -351,7 +351,7 @@ class TestIsolatedExecution(TestJobExecution):
|
|||||||
extra_vars = json.loads(extra_vars)
|
extra_vars = json.loads(extra_vars)
|
||||||
assert extra_vars['dest'] == '/tmp'
|
assert extra_vars['dest'] == '/tmp'
|
||||||
assert extra_vars['src'] == private_data
|
assert extra_vars['src'] == private_data
|
||||||
assert extra_vars['proot_temp_dir'].startswith('/tmp/ansible_tower_proot_')
|
assert extra_vars['proot_temp_dir'].startswith('/tmp/ansible_awx_proot_')
|
||||||
|
|
||||||
def test_systemctl_failure(self):
|
def test_systemctl_failure(self):
|
||||||
# If systemctl fails, read the contents of `artifacts/systemctl_logs`
|
# If systemctl fails, read the contents of `artifacts/systemctl_logs`
|
||||||
@@ -364,7 +364,7 @@ class TestIsolatedExecution(TestJobExecution):
|
|||||||
)
|
)
|
||||||
self.instance.credential = credential
|
self.instance.credential = credential
|
||||||
|
|
||||||
private_data = tempfile.mkdtemp(prefix='ansible_tower_')
|
private_data = tempfile.mkdtemp(prefix='ansible_awx_')
|
||||||
self.task.build_private_data_dir = mock.Mock(return_value=private_data)
|
self.task.build_private_data_dir = mock.Mock(return_value=private_data)
|
||||||
inventory = json.dumps({"all": {"hosts": ["localhost"]}})
|
inventory = json.dumps({"all": {"hosts": ["localhost"]}})
|
||||||
|
|
||||||
@@ -464,7 +464,7 @@ class TestJobCredentials(TestJobExecution):
|
|||||||
)
|
)
|
||||||
return ['successful', 0]
|
return ['successful', 0]
|
||||||
|
|
||||||
private_data = tempfile.mkdtemp(prefix='ansible_tower_')
|
private_data = tempfile.mkdtemp(prefix='ansible_awx_')
|
||||||
self.task.build_private_data_dir = mock.Mock(return_value=private_data)
|
self.task.build_private_data_dir = mock.Mock(return_value=private_data)
|
||||||
self.run_pexpect.side_effect = partial(run_pexpect_side_effect, private_data)
|
self.run_pexpect.side_effect = partial(run_pexpect_side_effect, private_data)
|
||||||
self.task.run(self.pk, private_data_dir=private_data)
|
self.task.run(self.pk, private_data_dir=private_data)
|
||||||
@@ -1145,7 +1145,7 @@ class TestProjectUpdateCredentials(TestJobExecution):
|
|||||||
assert 'bob' in kwargs.get('expect_passwords').values()
|
assert 'bob' in kwargs.get('expect_passwords').values()
|
||||||
return ['successful', 0]
|
return ['successful', 0]
|
||||||
|
|
||||||
private_data = tempfile.mkdtemp(prefix='ansible_tower_')
|
private_data = tempfile.mkdtemp(prefix='ansible_awx_')
|
||||||
self.task.build_private_data_dir = mock.Mock(return_value=private_data)
|
self.task.build_private_data_dir = mock.Mock(return_value=private_data)
|
||||||
self.run_pexpect.side_effect = partial(run_pexpect_side_effect, private_data)
|
self.run_pexpect.side_effect = partial(run_pexpect_side_effect, private_data)
|
||||||
self.task.run(self.pk)
|
self.task.run(self.pk)
|
||||||
|
|||||||
@@ -655,7 +655,7 @@ def build_proot_temp_dir():
|
|||||||
Create a temporary directory for proot to use.
|
Create a temporary directory for proot to use.
|
||||||
'''
|
'''
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
path = tempfile.mkdtemp(prefix='ansible_tower_proot_', dir=settings.AWX_PROOT_BASE_PATH)
|
path = tempfile.mkdtemp(prefix='ansible_awx_proot_', dir=settings.AWX_PROOT_BASE_PATH)
|
||||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
- name: Get capacity of the instance
|
- name: Get capacity of the instance
|
||||||
tower_capacity:
|
awx_capacity:
|
||||||
|
|
||||||
- name: Remove any stale temporary files
|
- name: Remove any stale temporary files
|
||||||
tower_isolated_cleanup:
|
awx_isolated_cleanup:
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def main():
|
|||||||
job_cutoff = datetime.datetime.now() - datetime.timedelta(hours=1)
|
job_cutoff = datetime.datetime.now() - datetime.timedelta(hours=1)
|
||||||
|
|
||||||
for search_pattern in [
|
for search_pattern in [
|
||||||
'/tmp/ansible_tower_[0-9]*_*', '/tmp/ansible_tower_proot_*',
|
'/tmp/ansible_awx_[0-9]*_*', '/tmp/ansible_awx_proot_*',
|
||||||
]:
|
]:
|
||||||
for path in glob.iglob(search_pattern):
|
for path in glob.iglob(search_pattern):
|
||||||
st = os.stat(path)
|
st = os.stat(path)
|
||||||
@@ -49,7 +49,7 @@ def main():
|
|||||||
continue
|
continue
|
||||||
elif modtime > folder_cutoff:
|
elif modtime > folder_cutoff:
|
||||||
try:
|
try:
|
||||||
re_match = re.match(r'\/tmp\/ansible_tower_\d+_.+', path)
|
re_match = re.match(r'\/tmp\/ansible_awx_\d+_.+', path)
|
||||||
if re_match is not None:
|
if re_match is not None:
|
||||||
if subprocess.check_call(['awx-expect', 'is-alive', path]) == 0:
|
if subprocess.check_call(['awx-expect', 'is-alive', path]) == 0:
|
||||||
continue
|
continue
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
docker build --no-cache=true --rm=true -t ansible/tower_devel:latest .
|
docker build --no-cache=true --rm=true -t ansible/awx_devel:latest .
|
||||||
docker run --name tower_test -it --memory="4g" --cpuset="0,1" -v /Users/meyers/ansible/:/tower_devel -p 8013:8013 -p 8080:8080 -p 27017:27017 -p 2222:22 ansible/tower_devel
|
docker run --name awx_test -it --memory="4g" --cpuset="0,1" -v /Users/meyers/ansible/:/awx_devel -p 8013:8013 -p 8080:8080 -p 27017:27017 -p 2222:22 ansible/awx_devel
|
||||||
|
|
||||||
## How to use the logstash container
|
## How to use the logstash container
|
||||||
|
|
||||||
|
|||||||
@@ -56,12 +56,12 @@ by disabling some parts of the cleanup_isolated.yml playbook.
|
|||||||
|
|
||||||
Example location of a private data directory:
|
Example location of a private data directory:
|
||||||
|
|
||||||
`/tmp/ansible_tower_29_OM6Mnx/`
|
`/tmp/ansible_awx_29_OM6Mnx/`
|
||||||
|
|
||||||
The following command would run the playbook corresponding to that job.
|
The following command would run the playbook corresponding to that job.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
awx-expect start /tmp/ansible_tower_29_OM6Mnx/
|
awx-expect start /tmp/ansible_awx_29_OM6Mnx/
|
||||||
```
|
```
|
||||||
|
|
||||||
Other awx-expect commands include `start`, `is-alive`, and `stop`.
|
Other awx-expect commands include `start`, `is-alive`, and `stop`.
|
||||||
|
|||||||
Reference in New Issue
Block a user