def test_interface_add_already_exists(self, mock_run_cmd): service_exists = [ 'systemctl', 'show', 'unknown.service', '--property=LoadError' ] not_found_output = \ 'LoadError=org.freedesktop.DBus.Error.FileNotFound '\ '"No such file or directory"' mock_run_cmd.return_value = [not_found_output, '', 0] expected_error_msg = "GINSERV00002E" with self.assertRaisesRegexp(NotFoundError, expected_error_msg): ServiceModel().lookup('unknown.service') mock_run_cmd.assert_called_once_with(service_exists)
def test_service_lookup(self, mock_run_cmd): call_service_exists = [ 'systemctl', 'show', 'wokd.service', '--property=LoadError' ] service_exists_return = ['LoadError=""', '', 0] call_systemctl_show = [ 'systemctl', 'show', 'wokd.service', '--property=LoadState,ActiveState,' 'SubState,Description,UnitFileState,ControlGroup' ] systemctl_show_return = [self.get_systemctl_show_output(), '', 0] call_systemd_cgls = [ 'systemd-cgls', '--no-pager', '/system.slice/wokd.service' ] systemd_cgls_return = [self.get_systemdcgls_output(), '', 0] mock_run_cmd_calls = [ call(call_service_exists), call(call_systemctl_show), call(call_systemd_cgls) ] mock_run_cmd.side_effect = [ service_exists_return, systemctl_show_return, systemd_cgls_return ] lookup_dict = ServiceModel().lookup('wokd.service') mock_run_cmd.assert_has_calls(mock_run_cmd_calls) self.assertEqual(lookup_dict.get('desc'), 'Wok - Webserver Originated from Kimchi') self.assertEqual(lookup_dict.get('name'), 'wokd.service') self.assertEqual(lookup_dict.get('load'), 'loaded') self.assertEqual(lookup_dict.get('active'), 'active') self.assertEqual(lookup_dict.get('sub'), 'running') self.assertEqual(lookup_dict.get('autostart'), False) cgroup_dict = { 'name': '/system.slice/wokd.service', 'processes': { '25775': 'python2 /usr/bin/wokd', '26011': 'nginx: master process nginx -c ' '/etc/nginx/...', '26012': 'nginx: worker process' } } self.assertEqual(lookup_dict.get('cgroup'), cgroup_dict)
def test_service_lookup(self, mock_run_cmd): call_service_exists = [ 'systemctl', 'show', 'wokd.service', '--property=LoadError' ] service_exists_return = ['LoadError=""', '', 0] call_systemctl_show = [ 'systemctl', 'show', 'wokd.service', '--property=LoadState,ActiveState,' 'SubState,Description,UnitFileState,ControlGroup' ] systemctl_show_return = [self.get_systemctl_show_output(), '', 0] call_systemd_cgls = ['systemd-cgls', '--no-pager', '/system.slice/wokd.service'] systemd_cgls_return = [self.get_systemdcgls_output(), '', 0] mock_run_cmd_calls = [ call(call_service_exists), call(call_systemctl_show), call(call_systemd_cgls) ] mock_run_cmd.side_effect = [ service_exists_return, systemctl_show_return, systemd_cgls_return ] lookup_dict = ServiceModel().lookup('wokd.service') mock_run_cmd.assert_has_calls(mock_run_cmd_calls) self.assertEqual( lookup_dict.get('desc'), 'Wok - Webserver Originated from Kimchi' ) self.assertEqual(lookup_dict.get('name'), 'wokd.service') self.assertEqual(lookup_dict.get('load'), 'loaded') self.assertEqual(lookup_dict.get('active'), 'active') self.assertEqual(lookup_dict.get('sub'), 'running') self.assertEqual(lookup_dict.get('autostart'), False) cgroup_dict = { 'name': '/system.slice/wokd.service', 'processes': { '25775': 'python2 /usr/bin/wokd', '26011': 'nginx: master process nginx -c ' '/etc/nginx/...', '26012': 'nginx: worker process' } } self.assertEqual(lookup_dict.get('cgroup'), cgroup_dict)
def test_service_restart(self, mock_run_cmd): cmd = ['systemctl', 'restart', 'wokd.service'] mock_run_cmd.return_value = ['', '', 0] ServiceModel().restart('wokd.service') mock_run_cmd.assert_called_once_with(cmd)
def test_service_disable(self, mock_run_cmd): cmd = ['systemctl', 'disable', 'wokd.service'] mock_run_cmd.return_value = ['', '', 0] ServiceModel().disable('wokd.service') mock_run_cmd.assert_called_once_with(cmd)