|
|
|
@ -290,63 +290,3 @@ class TestRunner(unittest.TestCase):
|
|
|
|
|
print result
|
|
|
|
|
assert result['changed'] == False
|
|
|
|
|
|
|
|
|
|
def test_apt_key(self):
|
|
|
|
|
try:
|
|
|
|
|
key_file = self._get_test_file("apt_key.gpg")
|
|
|
|
|
key_file_url = 'file://' + urllib2.quote(key_file)
|
|
|
|
|
key_id = '473041FA'
|
|
|
|
|
|
|
|
|
|
os.environ['ANSIBLE_TEST_APT_KEY'] = 'none'
|
|
|
|
|
# key missing, should download and add
|
|
|
|
|
result = self._run('apt_key', ['state=present', 'url=' + key_file_url])
|
|
|
|
|
assert 'failed' not in result
|
|
|
|
|
assert result['added'] == 1
|
|
|
|
|
assert result['downloaded'] == 1
|
|
|
|
|
assert result['removed'] == 0
|
|
|
|
|
assert result['changed']
|
|
|
|
|
|
|
|
|
|
os.environ["ANSIBLE_TEST_APT_KEY"] = key_id
|
|
|
|
|
# key missing, shouldn't download, no changes
|
|
|
|
|
result = self._run('apt_key', ['id=12345678', 'state=absent', 'url=' + key_file_url])
|
|
|
|
|
assert 'failed' not in result
|
|
|
|
|
assert result['added'] == 0
|
|
|
|
|
assert result['downloaded'] == 0
|
|
|
|
|
assert result['removed'] == 0
|
|
|
|
|
assert not result['changed']
|
|
|
|
|
# key missing, should download and fail sanity check, no changes
|
|
|
|
|
result = self._run('apt_key', ['id=12345678', 'state=present', 'url=' + key_file_url])
|
|
|
|
|
assert 'failed' in result
|
|
|
|
|
assert result['added'] == 0
|
|
|
|
|
assert result['downloaded'] == 1
|
|
|
|
|
assert result['removed'] == 0
|
|
|
|
|
# key present, shouldn't download, no changes
|
|
|
|
|
result = self._run('apt_key', ['id=' + key_id, 'state=present', 'url=' + key_file_url])
|
|
|
|
|
assert 'failed' not in result
|
|
|
|
|
assert result['added'] == 0
|
|
|
|
|
assert result['downloaded'] == 0
|
|
|
|
|
assert result['removed'] == 0
|
|
|
|
|
assert not result['changed']
|
|
|
|
|
# key present, should download to get key id
|
|
|
|
|
result = self._run('apt_key', ['state=present', 'url=' + key_file_url])
|
|
|
|
|
assert 'failed' not in result
|
|
|
|
|
assert result['added'] == 0
|
|
|
|
|
assert result['downloaded'] == 1
|
|
|
|
|
assert result['removed'] == 0
|
|
|
|
|
assert not result['changed']
|
|
|
|
|
# key present, should download to get key id and remove
|
|
|
|
|
result = self._run('apt_key', ['state=absent', 'url=' + key_file_url])
|
|
|
|
|
assert 'failed' not in result
|
|
|
|
|
assert result['added'] == 0
|
|
|
|
|
assert result['downloaded'] == 1
|
|
|
|
|
assert result['removed'] == 1
|
|
|
|
|
assert result['changed']
|
|
|
|
|
# key present, should remove but not download
|
|
|
|
|
result = self._run('apt_key', ['id=' + key_id, 'state=absent', 'url=' + key_file_url])
|
|
|
|
|
assert 'failed' not in result
|
|
|
|
|
assert result['added'] == 0
|
|
|
|
|
assert result['downloaded'] == 0
|
|
|
|
|
assert result['removed'] == 1
|
|
|
|
|
assert result['changed']
|
|
|
|
|
finally:
|
|
|
|
|
# always clean up the environment
|
|
|
|
|
os.environ.pop('ANSIBLE_TEST_APT_KEY', None)
|
|
|
|
|