class TestRHEL(TestLinux): def setUp(self): super(self.__class__, self).setUp() self.rhel = RHEL(self.params) def test_config_dir(self): self.assertEqual(self.config_dir, self.rhel.CONFIG_DIR) def test_config_file(self): self.assertEqual(self.config_file, self.rhel.CONFIG_FILE) def test_config_path(self): self.assertEqual(self.config_path, self.rhel.CONFIG_PATH) def test_installer(self): self.assertEqual(self.installer, self.rhel.INSTALLER) @mock.patch('os.geteuid', create=True) def test_validate_administrator_throws(self, geteuid): geteuid.return_value = 1 with self.assertRaisesRegex(RuntimeError, 'You must run this command as sudo.'): self.rhel.validate_administrator() def test_install(self): process = mock.MagicMock() process.communicate.return_value = ('', '') process.returncode = 0 self.popen.return_value = process self.rhel.install(self.params) self.popen.assert_has_calls([ mock.call(['service', 'codedeploy-agent', 'stop'], stdout=subprocess.PIPE, stderr=subprocess.PIPE), mock.call().communicate() ]) self.check_call.assert_has_calls([ mock.call(['yum', '-y', 'install', 'ruby']), mock.call(['chmod', '+x', './{0}'.format(self.installer)]), mock.call(['./{0}'.format(self.installer), 'auto'], env=self.environment) ]) self.open.assert_called_with(self.installer, 'wb') self.open().write.assert_called_with(self.body) def test_uninstall(self): process = mock.MagicMock() process.communicate.return_value = ('', '') process.returncode = 0 self.popen.return_value = process self.rhel.uninstall(self.params) self.popen.assert_has_calls([ mock.call(['service', 'codedeploy-agent', 'stop'], stdout=subprocess.PIPE, stderr=subprocess.PIPE), mock.call().communicate() ]) self.check_call.assert_has_calls( [mock.call(['yum', '-y', 'erase', 'codedeploy-agent'])])
def validate_instance(params): if platform.system() == 'Linux': if 'Ubuntu' in platform.linux_distribution()[0]: params.system = Ubuntu(params) if 'Red Hat Enterprise Linux Server' in platform.linux_distribution( )[0]: params.system = RHEL(params) elif platform.system() == 'Windows': params.system = Windows(params) if 'system' not in params: raise RuntimeError(System.UNSUPPORTED_SYSTEM_MSG) try: urlopen('http://169.254.169.254/latest/meta-data/', timeout=1) raise RuntimeError('Amazon EC2 instances are not supported.') except (URLError, timeout): pass
def setUp(self): super(self.__class__, self).setUp() self.rhel = RHEL(self.params)
class TestRHEL(TestLinux): def setUp(self): super(self.__class__, self).setUp() self.rhel = RHEL(self.params) def test_config_dir(self): self.assertEquals(self.config_dir, self.rhel.CONFIG_DIR) def test_config_file(self): self.assertEquals(self.config_file, self.rhel.CONFIG_FILE) def test_config_path(self): self.assertEquals(self.config_path, self.rhel.CONFIG_PATH) def test_installer(self): self.assertEquals(self.installer, self.rhel.INSTALLER) @patch('os.geteuid') def test_validate_administrator_throws(self, geteuid): geteuid.return_value = 1 with self.assertRaisesRegexp( RuntimeError, 'You must run this command as sudo.'): self.rhel.validate_administrator() def test_install(self): process = MagicMock() process.communicate.return_value = ('', '') process.returncode = 0 self.popen.return_value = process self.rhel.install(self.params) self.popen.assert_has_calls([ call( ['service', 'codedeploy-agent', 'stop'], stdout=subprocess.PIPE, stderr=subprocess.PIPE ), call().communicate() ]) self.check_call.assert_has_calls([ call(['yum', '-y', 'install', 'ruby']), call(['chmod', '+x', './{0}'.format(self.installer)]), call( ['./{0}'.format(self.installer), 'auto'], env=self.environment ) ]) self.open.assert_called_with(self.installer, 'wb') self.open().write.assert_called_with(self.body) def test_uninstall(self): process = MagicMock() process.communicate.return_value = ('', '') process.returncode = 0 self.popen.return_value = process self.rhel.uninstall(self.params) self.popen.assert_has_calls([ call( ['service', 'codedeploy-agent', 'stop'], stdout=subprocess.PIPE, stderr=subprocess.PIPE ), call().communicate() ]) self.check_call.assert_has_calls([ call(['yum', '-y', 'erase', 'codedeploy-agent']) ])