Beispiel #1
0
    def test_services_handler_sysv_disabled_service_updaterc(self):
        self.m.StubOutWithMock(os.path, 'exists')
        os.path.exists('/bin/systemctl').MultipleTimes().AndReturn(False)
        os.path.exists('/sbin/service').MultipleTimes().AndReturn(False)
        os.path.exists('/sbin/chkconfig').MultipleTimes().AndReturn(False)
        # apply_services
        self.mock_cmd_run(
            ['su', 'root', '-c',
             '/usr/sbin/update-rc.d httpd disable']).AndReturn(FakePOpen())
        self.mock_cmd_run(
            ['su', 'root', '-c',
             '/usr/sbin/service httpd status']).AndReturn(FakePOpen())
        self.mock_cmd_run(['su', 'root', '-c', '/usr/sbin/service httpd stop'
                           ]).AndReturn(FakePOpen())

        self.m.ReplayAll()

        services = {
            "sysvinit": {
                "httpd": {
                    "enabled": "false",
                    "ensureRunning": "false"
                }
            }
        }
        hooks = [
            cfn_helper.Hook('hook1', 'service.restarted',
                            'Resources.resource1.Metadata', 'root',
                            '/bin/services_restarted')
        ]
        sh = cfn_helper.ServicesHandler(services, 'resource1', hooks)
        sh.apply_services()

        self.m.VerifyAll()
Beispiel #2
0
    def test_services_handler_sysv_service_chkconfig(self):
        self.m.StubOutWithMock(os.path, 'exists')
        os.path.exists('/bin/systemctl').MultipleTimes().AndReturn(False)
        os.path.exists('/sbin/service').MultipleTimes().AndReturn(True)
        os.path.exists('/sbin/chkconfig').MultipleTimes().AndReturn(True)
        # apply_services
        self.mock_cmd_run(
            ['su', 'root', '-c', '/sbin/chkconfig httpd on']
        ).AndReturn(FakePOpen())
        self.mock_cmd_run(
            ['su', 'root', '-c', '/sbin/service httpd status']
        ).AndReturn(FakePOpen(returncode=-1))
        self.mock_cmd_run(
            ['su', 'root', '-c', '/sbin/service httpd start']
        ).AndReturn(FakePOpen())

        # monitor_services not running
        self.mock_cmd_run(
            ['su', 'root', '-c', '/sbin/service httpd status']
        ).AndReturn(FakePOpen(returncode=-1))
        self.mock_cmd_run(
            ['su', 'root', '-c', '/sbin/service httpd start']
        ).AndReturn(FakePOpen())
        self.mock_cmd_run(
            ['su', 'root', '-c', '/bin/services_restarted']
        ).AndReturn(FakePOpen())

        # monitor_services running
        self.mock_cmd_run(
            ['su', 'root', '-c', '/sbin/service httpd status']
        ).AndReturn(FakePOpen())

        self.m.ReplayAll()

        services = {
            "sysvinit": {
                "httpd": {"enabled": "true", "ensureRunning": "true"}
            }
        }
        hooks = [
            cfn_helper.Hook(
                'hook1',
                'service.restarted',
                'Resources.resource1.Metadata',
                'root',
                '/bin/services_restarted')
        ]
        sh = cfn_helper.ServicesHandler(services, 'resource1', hooks)
        sh.apply_services()
        # services not running
        sh.monitor_services()

        # services running
        sh.monitor_services()

        self.m.VerifyAll()
Beispiel #3
0
    def test_services_handler_systemd_disabled(self):
        self.m.StubOutWithMock(os.path, 'exists')
        os.path.exists('/bin/systemctl').MultipleTimes().AndReturn(True)
        # apply_services
        self.mock_cmd_run(
            ['su', 'root', '-c',
             '/bin/systemctl disable httpd.service']).AndReturn(FakePOpen())
        self.mock_cmd_run(
            ['su', 'root', '-c',
             '/bin/systemctl status httpd.service']).AndReturn(FakePOpen())
        self.mock_cmd_run(
            ['su', 'root', '-c',
             '/bin/systemctl stop httpd.service']).AndReturn(FakePOpen())
        self.mock_cmd_run(
            ['su', 'root', '-c',
             '/bin/systemctl disable mysqld.service']).AndReturn(FakePOpen())
        self.mock_cmd_run(
            ['su', 'root', '-c',
             '/bin/systemctl status mysqld.service']).AndReturn(FakePOpen())
        self.mock_cmd_run(
            ['su', 'root', '-c',
             '/bin/systemctl stop mysqld.service']).AndReturn(FakePOpen())

        self.m.ReplayAll()

        services = {
            "systemd": {
                "mysqld": {
                    "enabled": "false",
                    "ensureRunning": "false"
                },
                "httpd": {
                    "enabled": "false",
                    "ensureRunning": "false"
                }
            }
        }
        hooks = [
            cfn_helper.Hook('hook1', 'service.restarted',
                            'Resources.resource1.Metadata', 'root',
                            '/bin/services_restarted')
        ]
        sh = cfn_helper.ServicesHandler(services, 'resource1', hooks)
        sh.apply_services()

        self.m.VerifyAll()