예제 #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()
예제 #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()
예제 #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()
예제 #4
0
    def _test_cfn_hup_metadata(self, metadata):

        self._mock_retrieve_metadata(metadata)
        FakeServicesHandler = mock.Mock()
        FakeServicesHandler.monitor_services.return_value = None
        self.useFixture(
            fixtures.MonkeyPatch(
                'heat_cfntools.cfntools.cfn_helper.ServicesHandler',
                FakeServicesHandler))

        section = self.getUniqueString()
        triggers = 'post.add,post.delete,post.update'
        path = 'Resources.%s.Metadata' % self.resource
        runas = 'root'
        action = '/bin/sh -c "true"'
        hook = cfn_helper.Hook(section, triggers, path, runas, action)

        with mock.patch.object(cfn_helper.Hook, 'event') as mock_method:
            mock_method.return_value = None
            self.metadata.cfn_hup([hook])
예제 #5
0
    def _test_cfn_hup_metadata(self, metadata):

        self._mock_retrieve_metadata(metadata)
        self.useFixture(
            fixtures.MonkeyPatch(
                'heat_cfntools.cfntools.cfn_helper.ServicesHandler',
                FakeServicesHandler))

        section = self.getUniqueString()
        triggers = 'post.add,post.delete,post.update'
        path = 'Resources.%s.Metadata' % self.resource
        runas = 'root'
        action = '/bin/sh -c "true"'
        hook = cfn_helper.Hook(section, triggers, path, runas, action)
        self.m.StubOutWithMock(hook, 'event')
        hook.event('post.update', self.resource, self.resource).AndReturn(None)
        self.m.ReplayAll()

        self.metadata.cfn_hup([hook])
        self.m.VerifyAll()
        self.m.UnsetStubs()