Merge remote-tracking branch 'origin/unienv'
* origin/unienv: docs: update Changelog. issue #600: /etc/environment may be non-ASCII in an unknown encoding docs: finished Changelog locking note Fix for sample in doc docs: break out install_app.py and fix API use.pull/612/head
commit
5c39f58edf
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
"""
|
||||||
|
Install our application on a remote machine.
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
install_app.py <hostname>
|
||||||
|
|
||||||
|
Where:
|
||||||
|
<hostname> Hostname to install to.
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import mitogen
|
||||||
|
|
||||||
|
|
||||||
|
def install_app():
|
||||||
|
os.system('tar zxvf my_app.tar.gz')
|
||||||
|
|
||||||
|
|
||||||
|
@mitogen.main()
|
||||||
|
def main(router):
|
||||||
|
if len(sys.argv) != 2:
|
||||||
|
print(__doc__)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
context = router.ssh(hostname=sys.argv[1])
|
||||||
|
context.call(install_app)
|
@ -0,0 +1,74 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
import mock
|
||||||
|
import unittest2
|
||||||
|
import testlib
|
||||||
|
|
||||||
|
from mitogen.core import b
|
||||||
|
import ansible_mitogen.runner
|
||||||
|
|
||||||
|
|
||||||
|
klass = ansible_mitogen.runner.EnvironmentFileWatcher
|
||||||
|
environb = getattr(os, 'environb', os.environ)
|
||||||
|
|
||||||
|
|
||||||
|
class WatcherTest(testlib.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.original_env = environb.copy()
|
||||||
|
self.tf = tempfile.NamedTemporaryFile()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.tf.close()
|
||||||
|
environb.clear()
|
||||||
|
environb.update(self.original_env)
|
||||||
|
|
||||||
|
def test_missing_file(self):
|
||||||
|
# just ensure it doesn't crash
|
||||||
|
watcher = klass('/nonexistent')
|
||||||
|
watcher.check()
|
||||||
|
|
||||||
|
def test_file_becomes_missing(self):
|
||||||
|
# just ensure it doesn't crash
|
||||||
|
watcher = klass(self.tf.name)
|
||||||
|
watcher.check()
|
||||||
|
os.unlink(self.tf.name)
|
||||||
|
watcher.check()
|
||||||
|
open(self.tf.name,'wb').close()
|
||||||
|
|
||||||
|
def test_key_deleted(self):
|
||||||
|
environb[b('SOMEKEY')] = b('123')
|
||||||
|
self.tf.write(b('SOMEKEY=123\n'))
|
||||||
|
self.tf.flush()
|
||||||
|
watcher = klass(self.tf.name)
|
||||||
|
self.tf.seek(0)
|
||||||
|
self.tf.truncate(0)
|
||||||
|
watcher.check()
|
||||||
|
self.assertTrue(b('SOMEKEY') not in environb)
|
||||||
|
|
||||||
|
def test_key_added(self):
|
||||||
|
watcher = klass(self.tf.name)
|
||||||
|
self.tf.write(b('SOMEKEY=123\n'))
|
||||||
|
self.tf.flush()
|
||||||
|
watcher.check()
|
||||||
|
self.assertEqual(environb[b('SOMEKEY')], b('123'))
|
||||||
|
|
||||||
|
def test_key_shadowed_nuchange(self):
|
||||||
|
environb[b('SOMEKEY')] = b('234')
|
||||||
|
self.tf.write(b('SOMEKEY=123\n'))
|
||||||
|
self.tf.flush()
|
||||||
|
watcher = klass(self.tf.name)
|
||||||
|
watcher.check()
|
||||||
|
self.assertEqual(environb[b('SOMEKEY')], b('234'))
|
||||||
|
|
||||||
|
def test_binary_key_added(self):
|
||||||
|
watcher = klass(self.tf.name)
|
||||||
|
self.tf.write(b('SOMEKEY=\xff\xff\xff\n'))
|
||||||
|
self.tf.flush()
|
||||||
|
watcher.check()
|
||||||
|
self.assertEqual(environb[b('SOMEKEY')], b('\xff\xff\xff'))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest2.main()
|
Loading…
Reference in New Issue