ubuntu-server-ec2-testing-dev team mailing list archive
-
ubuntu-server-ec2-testing-dev team
-
Mailing list archive
-
Message #00017
[Merge] lp:~daniel-thewatkins/ec2-automated-tests/refactor-duplication into lp:ec2-automated-tests
Daniel Watkins has proposed merging lp:~daniel-thewatkins/ec2-automated-tests/refactor-duplication into lp:ec2-automated-tests.
Requested reviews:
Ben Howard (utlemming)
For more details, see:
https://code.launchpad.net/~daniel-thewatkins/ec2-automated-tests/refactor-duplication/+merge/234444
--
https://code.launchpad.net/~daniel-thewatkins/ec2-automated-tests/refactor-duplication/+merge/234444
Your team Ubuntu Server ec2 Testing Developers is subscribed to branch lp:ec2-automated-tests.
=== modified file 'cloud-config/test.py'
--- cloud-config/test.py 2012-02-02 10:35:07 +0000
+++ cloud-config/test.py 2014-09-12 09:35:13 +0000
@@ -1,69 +1,36 @@
#!/usr/bin/python
-#
+#
# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
#
# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
+#
+# ubuntu-server-ec2-testing is free software: you can redistribute it
+# and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+#
+# ubuntu-server-ec2-testing is distributed in the hope that it will
+# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
+# along with ubuntu-server-ec2-testing. If not, see
# <http://www.gnu.org/licenses/>.
-#
+#
import logging
import os.path
import unittest
import subprocess
+from shared_tests import SharedInInstanceEC2Tests
+
+
logging.basicConfig(level=logging.DEBUG)
-SUDO_CONFIG = '(ALL) NOPASSWD: ALL'
-
class CloudConfigEC2Test(unittest.TestCase):
- def testSudo(self):
- cmd = ['sudo', '-l','-U','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue(SUDO_CONFIG in output,output)
- cmd = ['su','-c','sudo echo Hello World','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testReadWrite(self):
- t_fh = open(os.path.join('/tmp', 'a'), 'w')
- self.assertNotEqual(t_fh, None)
- self.assertEqual(t_fh.write('a'), None)
- self.assertEqual(t_fh.close(), None)
-
- def testOpenSSHDaemon(self):
- cmd = ['pgrep', 'sshd']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output, '')
-
- def testOpenPorts(self):
- cmd = ['netstat', '-atuvpn']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- output2 = filter(lambda l: int(l.split()[3].split(':')[-1]) == 22,
- output.strip().split('\n')[2:])
- self.assertTrue(len(output2) >= 2, output2)
-
def testMirror(self):
cmd = ['grep','us.archive.ubuntu.com','/etc/apt/sources.list']
logging.debug('Cmd: %s' % (cmd))
@@ -102,7 +69,7 @@
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
logging.debug('Cmd output: %s' % (output))
- # Should not be / volume so this should work
+ # Should not be / volume so this should work
self.assertTrue('/opt' in output, output)
def testSwap(self):
=== modified file 'cloud-config/test_remote.py'
--- cloud-config/test_remote.py 2011-03-04 08:43:50 +0000
+++ cloud-config/test_remote.py 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
-#
-# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
-# <http://www.gnu.org/licenses/>.
-#
-
-import logging
-import os.path
-import unittest
-import subprocess
-
-logging.basicConfig(level=logging.DEBUG)
-
-class RemoteEC2Test(unittest.TestCase):
-
- def testUbuntuSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'ubuntu@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testRootSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'root@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Please login as' in output,output)
-
-if __name__ == '__main__':
- unittest.main()
=== target is u'../tools/test_remote.py'
=== modified file 'default/test.py'
--- default/test.py 2014-09-12 08:03:29 +0000
+++ default/test.py 2014-09-12 09:35:13 +0000
@@ -18,83 +18,9 @@
# along with ubuntu-server-ec2-testing. If not, see
# <http://www.gnu.org/licenses/>.
#
-
-import logging
-import os.path
import unittest
-import subprocess
-
-import apt
-
-logging.basicConfig(level=logging.DEBUG)
-
-SUDO_CONFIG = '(ALL) NOPASSWD: ALL'
-
-class InInstanceEC2Test(unittest.TestCase):
-
- def testSudo(self):
- cmd = ['sudo', '-l','-U','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue(SUDO_CONFIG in output,output)
- cmd = ['su','-c','sudo echo Hello World','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testReadWrite(self):
- t_fh = open(os.path.join('/tmp', 'a'), 'w')
- self.assertNotEqual(t_fh, None)
- self.assertEqual(t_fh.write('a'), None)
- self.assertEqual(t_fh.close(), None)
-
- def testOpenSSHDaemon(self):
- cmd = ['pgrep', 'sshd']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output, '')
-
- def testOpenPorts(self):
- cmd = ['netstat', '-atuvpn']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- output2 = filter(lambda l: int(l.split()[3].split(':')[-1]) == 22,
- output.strip().split('\n')[2:])
- self.assertTrue(len(output2) >= 2, output2)
-
- def testPackagesEqualToOrOlderThanArchive(self):
- logging.debug('Testing package versions')
- errors = []
- cache = apt.cache.Cache()
- cache.update()
- cache.open()
- installed_packages = (
- package for package in cache if package.is_installed)
- for package in installed_packages:
- available_versions = [
- version for version in package.versions if version.downloadable]
- if not available_versions:
- errors.append("{} does not appear to be available in the"
- " archives.".format(package.name))
- continue
- highest_available_version = max(
- [version for version in package.versions
- if version.downloadable])
- currently_installed_version = package.installed
- if not (highest_available_version >= currently_installed_version):
- errors.append(
- "The installed version of {} ({}) is higher than that"
- " available in the archives ({}).".format(
- package.name,
- currently_installed_version.version,
- highest_available_version.version)
- )
- if errors:
- self.fail("\n".join(errors))
+
+from shared_tests import SharedInInstanceEC2Tests
if __name__ == '__main__':
=== modified file 'default/test_remote.py'
--- default/test_remote.py 2011-03-04 08:43:50 +0000
+++ default/test_remote.py 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
-#
-# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
-# <http://www.gnu.org/licenses/>.
-#
-
-import logging
-import os.path
-import unittest
-import subprocess
-
-logging.basicConfig(level=logging.DEBUG)
-
-class RemoteEC2Test(unittest.TestCase):
-
- def testUbuntuSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'ubuntu@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testRootSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'root@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Please login as' in output,output)
-
-if __name__ == '__main__':
- unittest.main()
=== target is u'../tools/test_remote.py'
=== modified file 'global/execute_tests.sh'
--- global/execute_tests.sh 2011-06-02 11:00:04 +0000
+++ global/execute_tests.sh 2014-09-12 09:35:13 +0000
@@ -9,6 +9,7 @@
cd /tmp
bzr branch lp:~ubuntu-server-ec2-testing-dev/+junk/ec2-automated-tests tests
cd tests/${TEST_NAME}
+cp ../shared_tests.py .
sudo python -m subunit.run test | subunit2junitxml > /tmp/TEST-ininstance-${TEST_ID}-results.xml
# Always exit 0 so that testing does not stop
=== modified file 'multi-part-ud/test.py'
--- multi-part-ud/test.py 2011-03-03 21:52:36 +0000
+++ multi-part-ud/test.py 2014-09-12 09:35:13 +0000
@@ -1,121 +1,88 @@
#!/usr/bin/python
-#
+#
# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
#
# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
+#
+# ubuntu-server-ec2-testing is free software: you can redistribute it
+# and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+#
+# ubuntu-server-ec2-testing is distributed in the hope that it will
+# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
+# along with ubuntu-server-ec2-testing. If not, see
# <http://www.gnu.org/licenses/>.
-#
+#
import logging
import os.path
import unittest
import subprocess
+from shared_tests import SharedInInstanceEC2Tests
+
+
logging.basicConfig(level=logging.DEBUG)
-SUDO_CONFIG = '(ALL) NOPASSWD: ALL'
-
class MultiPartUserDataEC2Test(unittest.TestCase):
- def testSudo(self):
- cmd = ['sudo', '-l','-U','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue(SUDO_CONFIG in output,output)
- cmd = ['su','-c','sudo echo Hello World','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testReadWrite(self):
- t_fh = open(os.path.join('/tmp', 'a'), 'w')
- self.assertNotEqual(t_fh, None)
- self.assertEqual(t_fh.write('a'), None)
- self.assertEqual(t_fh.close(), None)
-
- def testOpenSSHDaemon(self):
- cmd = ['pgrep', 'sshd']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output, '')
-
- def testOpenPorts(self):
- cmd = ['netstat', '-atuvpn']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- output2 = filter(lambda l: int(l.split()[3].split(':')[-1]) == 22,
- output.strip().split('\n')[2:])
- self.assertTrue(len(output2) >= 2, output2)
-
def testScripts(self):
cmd = ['cat','/root/OUTPUT-my-user-script-1.sh']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
cmd = ['cat','/root/OUTPUT-my-user-script-1.sh']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
def testUpstart(self):
cmd = ['cat','/root/OUTPUT-my-upstart-job.conf']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
cmd = ['cat','/etc/init/my-upstart-job.conf']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
cmd = ['cat','/root/OUTPUT-upstartjob1.txt']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
cmd = ['cat','/etc/init/upstartjob1.txt.conf']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
-
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
+
def testIncludes(self):
cmd = ['cat','/root/OUTPUT-include-compressed-script-01.txt']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
cmd = ['cat','/root/OUTPUT-include-script-01.txt']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
-
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
+
def testPasteinitInstalled(self):
cmd = ['dpkg','-s','pastebinit']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output,'')
-
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output,'')
+
if __name__ == '__main__':
unittest.main()
=== modified file 'multi-part-ud/test_remote.py'
--- multi-part-ud/test_remote.py 2011-03-04 08:43:50 +0000
+++ multi-part-ud/test_remote.py 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
-#
-# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
-# <http://www.gnu.org/licenses/>.
-#
-
-import logging
-import os.path
-import unittest
-import subprocess
-
-logging.basicConfig(level=logging.DEBUG)
-
-class RemoteEC2Test(unittest.TestCase):
-
- def testUbuntuSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'ubuntu@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testRootSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'root@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Please login as' in output,output)
-
-if __name__ == '__main__':
- unittest.main()
=== target is u'../tools/test_remote.py'
=== modified file 'proposed/test.py'
--- proposed/test.py 2012-07-20 08:44:38 +0000
+++ proposed/test.py 2014-09-12 09:35:13 +0000
@@ -1,69 +1,36 @@
#!/usr/bin/python
-#
+#
# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
#
# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
+#
+# ubuntu-server-ec2-testing is free software: you can redistribute it
+# and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+#
+# ubuntu-server-ec2-testing is distributed in the hope that it will
+# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
+# along with ubuntu-server-ec2-testing. If not, see
# <http://www.gnu.org/licenses/>.
-#
+#
import logging
import os.path
import unittest
import subprocess
+from shared_tests import SharedInInstanceEC2Tests
+
+
logging.basicConfig(level=logging.DEBUG)
-SUDO_CONFIG = '(ALL) NOPASSWD: ALL'
-
class ProposedEC2Test(unittest.TestCase):
- def testSudo(self):
- cmd = ['sudo', '-l','-U','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue(SUDO_CONFIG in output,output)
- cmd = ['su','-c','sudo echo Hello World','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testReadWrite(self):
- t_fh = open(os.path.join('/tmp', 'a'), 'w')
- self.assertNotEqual(t_fh, None)
- self.assertEqual(t_fh.write('a'), None)
- self.assertEqual(t_fh.close(), None)
-
- def testOpenSSHDaemon(self):
- cmd = ['pgrep', 'sshd']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output, '')
-
- def testOpenPorts(self):
- cmd = ['netstat', '-atuvpn']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- output2 = filter(lambda l: int(l.split()[3].split(':')[-1]) == 22,
- output.strip().split('\n')[2:])
- self.assertTrue(len(output2) >= 2, output2)
-
def testProposedEnabled(self):
cmd = ['grep','proposed','/etc/apt/sources.list']
logging.debug('Cmd: %s' % (cmd))
=== modified file 'proposed/test_remote.py'
--- proposed/test_remote.py 2012-07-20 07:55:04 +0000
+++ proposed/test_remote.py 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
-#
-# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
-# <http://www.gnu.org/licenses/>.
-#
-
-import logging
-import os.path
-import unittest
-import subprocess
-
-logging.basicConfig(level=logging.DEBUG)
-
-class RemoteEC2Test(unittest.TestCase):
-
- def testUbuntuSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'ubuntu@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testRootSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'root@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Please login as' in output,output)
-
-if __name__ == '__main__':
- unittest.main()
=== target is u'../tools/test_remote.py'
=== added file 'shared_tests.py'
--- shared_tests.py 1970-01-01 00:00:00 +0000
+++ shared_tests.py 2014-09-12 09:35:13 +0000
@@ -0,0 +1,102 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2014, Canonical Ltd (http://www.canonical.com/)
+#
+# This file is part of ubuntu-server-ec2-testing.
+#
+# ubuntu-server-ec2-testing is free software: you can redistribute it
+# and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# ubuntu-server-ec2-testing is distributed in the hope that it will
+# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ubuntu-server-ec2-testing. If not, see
+# <http://www.gnu.org/licenses/>.
+#
+import logging
+import os.path
+import unittest
+import subprocess
+
+import apt
+
+logging.basicConfig(level=logging.DEBUG)
+
+SUDO_CONFIG = '(ALL) NOPASSWD: ALL'
+
+
+class SharedInInstanceEC2Tests(unittest.TestCase):
+ """
+ Tests that we want to run in each test type.
+
+ Just import in to the appropriate file and unittest will pick it up.
+ """
+
+ def testSudo(self):
+ cmd = ['sudo', '-l','-U','ubuntu']
+ logging.debug('Cmd: %s' % (cmd))
+ output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
+ logging.debug('Cmd output: %s' % (output))
+ self.assertTrue(SUDO_CONFIG in output,output)
+ cmd = ['su','-c','sudo echo Hello World','ubuntu']
+ logging.debug('Cmd: %s' % (cmd))
+ output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
+ logging.debug('Cmd output: %s' % (output))
+ self.assertTrue('Hello World' in output,output)
+
+ def testReadWrite(self):
+ t_fh = open(os.path.join('/tmp', 'a'), 'w')
+ self.assertNotEqual(t_fh, None)
+ self.assertEqual(t_fh.write('a'), None)
+ self.assertEqual(t_fh.close(), None)
+
+ def testOpenSSHDaemon(self):
+ cmd = ['pgrep', 'sshd']
+ logging.debug('Cmd: %s' % (cmd))
+ output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
+ logging.debug('Cmd output: %s' % (output))
+ self.assertNotEquals(output, '')
+
+ def testOpenPorts(self):
+ cmd = ['netstat', '-atuvpn']
+ logging.debug('Cmd: %s' % (cmd))
+ output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
+ logging.debug('Cmd output: %s' % (output))
+ output2 = filter(lambda l: int(l.split()[3].split(':')[-1]) == 22,
+ output.strip().split('\n')[2:])
+ self.assertTrue(len(output2) >= 2, output2)
+
+ def testPackagesEqualToOrOlderThanArchive(self):
+ logging.debug('Testing package versions')
+ errors = []
+ cache = apt.cache.Cache()
+ cache.update()
+ cache.open()
+ installed_packages = (
+ package for package in cache if package.is_installed)
+ for package in installed_packages:
+ available_versions = [
+ version for version in package.versions if version.downloadable]
+ if not available_versions:
+ errors.append("{} does not appear to be available in the"
+ " archives.".format(package.name))
+ continue
+ highest_available_version = max(
+ [version for version in package.versions
+ if version.downloadable])
+ currently_installed_version = package.installed
+ if not (highest_available_version >= currently_installed_version):
+ errors.append(
+ "The installed version of {} ({}) is higher than that"
+ " available in the archives ({}).".format(
+ package.name,
+ currently_installed_version.version,
+ highest_available_version.version)
+ )
+ if errors:
+ self.fail("\n".join(errors))
=== modified file 'simple-user-data/test.py'
--- simple-user-data/test.py 2011-04-05 13:22:36 +0000
+++ simple-user-data/test.py 2014-09-12 09:35:13 +0000
@@ -1,75 +1,42 @@
#!/usr/bin/python
-#
+#
# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
#
# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
+#
+# ubuntu-server-ec2-testing is free software: you can redistribute it
+# and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+#
+# ubuntu-server-ec2-testing is distributed in the hope that it will
+# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
+# along with ubuntu-server-ec2-testing. If not, see
# <http://www.gnu.org/licenses/>.
-#
+#
import logging
import os.path
import unittest
import subprocess
+from shared_tests import SharedInInstanceEC2Tests
+
+
logging.basicConfig(level=logging.DEBUG)
-SUDO_CONFIG = '(ALL) NOPASSWD: ALL'
-
class InInstanceEC2Test(unittest.TestCase):
- def testSudo(self):
- cmd = ['sudo', '-l','-U','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue(SUDO_CONFIG in output,output)
- cmd = ['su','-c','sudo echo Hello World','ubuntu']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testReadWrite(self):
- t_fh = open(os.path.join('/tmp', 'a'), 'w')
- self.assertNotEqual(t_fh, None)
- self.assertEqual(t_fh.write('a'), None)
- self.assertEqual(t_fh.close(), None)
-
- def testOpenSSHDaemon(self):
- cmd = ['pgrep', 'sshd']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertNotEquals(output, '')
-
- def testOpenPorts(self):
- cmd = ['netstat', '-atuvpn']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- output2 = filter(lambda l: int(l.split()[3].split(':')[-1]) == 22,
- output.strip().split('\n')[2:])
- self.assertTrue(len(output2) >= 2, output2)
-
def testSimpleUserData(self):
cmd = ['cat','/root/OUTPUT-simple-01.txt']
logging.debug('Cmd: %s' % (cmd))
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
+ logging.debug('Cmd output: %s' % (output))
+ self.assertTrue('Hello World' in output,output)
if __name__ == '__main__':
unittest.main()
=== modified file 'simple-user-data/test_remote.py'
--- simple-user-data/test_remote.py 2011-04-05 13:22:36 +0000
+++ simple-user-data/test_remote.py 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
-#
-# This file is part of ubuntu-server-ec2-testing.
-#
-# ubuntu-server-ec2-testing is free software: you can redistribute it
-# and/or modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation, either version 3 of
-# the License, or (at your option) any later version.
-#
-# ubuntu-server-ec2-testing is distributed in the hope that it will
-# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with ubuntu-server-ec2-testing. If not, see
-# <http://www.gnu.org/licenses/>.
-#
-
-import logging
-import os.path
-import unittest
-import subprocess
-
-logging.basicConfig(level=logging.DEBUG)
-
-class RemoteEC2Test(unittest.TestCase):
-
- def testUbuntuSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'ubuntu@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Hello World' in output,output)
-
- def testRootSSH(self):
- cmd = ['ssh', '-i', '{{ keyfile }}',
- '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
- 'root@{{ hostname }}',
- 'echo Hello World']
- logging.debug('Cmd: %s' % (cmd))
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
- logging.debug('Cmd output: %s' % (output))
- self.assertTrue('Please login as' in output,output)
-
-if __name__ == '__main__':
- unittest.main()
=== target is u'../tools/test_remote.py'
=== added file 'tools/test_remote.py'
--- tools/test_remote.py 1970-01-01 00:00:00 +0000
+++ tools/test_remote.py 2014-09-12 09:35:13 +0000
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2010, Canonical Ltd (http://www.canonical.com/)
+#
+# This file is part of ubuntu-server-ec2-testing.
+#
+# ubuntu-server-ec2-testing is free software: you can redistribute it
+# and/or modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# ubuntu-server-ec2-testing is distributed in the hope that it will
+# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ubuntu-server-ec2-testing. If not, see
+# <http://www.gnu.org/licenses/>.
+#
+
+import logging
+import os.path
+import unittest
+import subprocess
+
+logging.basicConfig(level=logging.DEBUG)
+
+class RemoteEC2Test(unittest.TestCase):
+
+ def testUbuntuSSH(self):
+ cmd = ['ssh', '-i', '{{ keyfile }}',
+ '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
+ 'ubuntu@{{ hostname }}',
+ 'echo Hello World']
+ logging.debug('Cmd: %s' % (cmd))
+ output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
+ logging.debug('Cmd output: %s' % (output))
+ self.assertTrue('Hello World' in output,output)
+
+ def testRootSSH(self):
+ cmd = ['ssh', '-i', '{{ keyfile }}',
+ '-o','UserKnownHostsFile={{ work_dir }}/host.keys',
+ 'root@{{ hostname }}',
+ 'echo Hello World']
+ logging.debug('Cmd: %s' % (cmd))
+ output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
+ logging.debug('Cmd output: %s' % (output))
+ self.assertTrue('Please login as' in output,output)
+
+if __name__ == '__main__':
+ unittest.main()
Follow ups