def setUp(self):

        os.environ[TEST_MACHINE_IP_ENV_VARIABLE] = '15.126.205.73'

        if TEST_MACHINE_IP_ENV_VARIABLE not in os.environ:
            raise RuntimeError('TEST_MACHINE_IP environment variable must '
                               'be set and point to an existing server with '
                               'WinRM configured properly')

        self.runner = WinRMRunner(
            session_config=WinRMRunnerTest._create_session()
        )
Esempio n. 2
0
    def setUp(self):

        os.environ[TEST_MACHINE_IP_ENV_VARIABLE] = '15.126.205.73'

        if TEST_MACHINE_IP_ENV_VARIABLE not in os.environ:
            raise RuntimeError('TEST_MACHINE_IP environment variable must '
                               'be set and point to an existing server with '
                               'WinRM configured properly')

        self.runner = WinRMRunner(
            session_config=WinRMRunnerTest._create_session()
        )
Esempio n. 3
0
    def test_full_lifecycle(self):
        tasks.install(ctx=self._create_context('install'))
        tasks.start(ctx=self._create_context('start'))

        def _create_session():
            return {
                'host': os.environ[TEST_MACHINE_IP_ENV_VARIABLE],
                'user': '******',
                'password': '******'
            }

        # Retrieve registered plugins
        from windows_agent_installer.winrm_runner import WinRMRunner
        from windows_agent_installer.tasks import RUNTIME_AGENT_PATH
        from windows_agent_installer.tasks import AGENT_EXEC_FILE_NAME
        runner = WinRMRunner(session_config=_create_session())
        response = runner.run(
            '{0}\Scripts\celery.exe inspect registered'
            .format(RUNTIME_AGENT_PATH))

        # Assert agent has necessary includes
        self.assertTrue(AGENT_INCLUDES in response.std_out)

        # Restart the service
        tasks.restart(ctx=self._create_context('restart'))

        # Stop the service
        tasks.stop(ctx=self._create_context('stop'))

        # Uninstall, delete the files
        tasks.uninstall(ctx=self._create_context('uninstall'))

        # Assert files are gone
        self.assertFalse(runner.exists(path=RUNTIME_AGENT_PATH))
        self.assertFalse(
            runner.exists(
                path='C:\{0}'.format(AGENT_EXEC_FILE_NAME)))
    def test_full_lifecycle(self):
        tasks.install(ctx=self._create_context('install'))
        tasks.start(ctx=self._create_context('start'))

        def _create_session():
            return {
                'host': os.environ[TEST_MACHINE_IP_ENV_VARIABLE],
                'user': '******',
                'password': '******'
            }

        # Retrieve registered plugins
        from windows_agent_installer.winrm_runner import WinRMRunner
        from windows_agent_installer.tasks import RUNTIME_AGENT_PATH
        from windows_agent_installer.tasks import AGENT_EXEC_FILE_NAME
        runner = WinRMRunner(session_config=_create_session())
        response = runner.run(
            '{0}\Scripts\celery.exe inspect registered'
            .format(RUNTIME_AGENT_PATH))

        # Assert agent has necessary includes
        self.assertTrue(AGENT_INCLUDES in response.std_out)

        # Restart the service
        tasks.restart(ctx=self._create_context('restart'))

        # Stop the service
        tasks.stop(ctx=self._create_context('stop'))

        # Uninstall, delete the files
        tasks.uninstall(ctx=self._create_context('uninstall'))

        # Assert files are gone
        self.assertFalse(runner.exists(path=RUNTIME_AGENT_PATH))
        self.assertFalse(
            runner.exists(
                path='C:\{0}'.format(AGENT_EXEC_FILE_NAME)))
Esempio n. 5
0
class TestTasks(unittest.TestCase):

    """
    Test cases for the worker installer functionality.
    These tests run PowerShell commands remotely on a WinRM enabled server.

    An existing server must be setup, set the 'TEST_MACHINE_IP'
    environment variable to the server IP,
    otherwise an exception will be raised.

    Note: These tests require a machine with RabbitMQ
    running for the celery worker to start properly.
    """

    @staticmethod
    def _create_context(task_name):

        cloudify_agent = {
            'user': '******',
            'password': '******'
        }

        properties = {
            'ip': os.environ[TEST_MACHINE_IP_ENV_VARIABLE],
            'cloudify_agent': cloudify_agent
        }

        return MockCloudifyContext(
            properties=properties,
            node_id='test-node-id',
            task_name=task_name
        )

    def setUp(self):

        os.environ[TEST_MACHINE_IP_ENV_VARIABLE] = '15.126.205.73'

        if TEST_MACHINE_IP_ENV_VARIABLE not in os.environ:
            raise RuntimeError('TEST_MACHINE_IP environment variable must '
                               'be set and point to an existing server with '
                               'WinRM configured properly')

        self.runner = WinRMRunner(
            session_config=WinRMRunnerTest._create_session()
        )

    def tearDown(self):
        try:
            tasks.stop(ctx=self._create_context('stop'))
        except BaseException as e:
            logger.error(e.message)
        try:
            tasks.uninstall(ctx=self._create_context('uninstall'))
        except BaseException as e:
            logger.warning(e.message)
            self.runner.delete(path=tasks.AGENT_FOLDER_NAME,
                               ignore_missing=True)
            self.runner.delete(
                path='C:\\{0}'.format(tasks.AGENT_EXEC_FILE_NAME),
                ignore_missing=True)

    def test_full_lifecycle(self):
        tasks.install(ctx=self._create_context('install'))
        tasks.start(ctx=self._create_context('start'))

        def _create_session():
            return {
                'host': os.environ[TEST_MACHINE_IP_ENV_VARIABLE],
                'user': '******',
                'password': '******'
            }

        # Retrieve registered plugins
        from windows_agent_installer.winrm_runner import WinRMRunner
        from windows_agent_installer.tasks import RUNTIME_AGENT_PATH
        from windows_agent_installer.tasks import AGENT_EXEC_FILE_NAME
        runner = WinRMRunner(session_config=_create_session())
        response = runner.run(
            '{0}\Scripts\celery.exe inspect registered'
            .format(RUNTIME_AGENT_PATH))

        # Assert agent has necessary includes
        self.assertTrue(AGENT_INCLUDES in response.std_out)

        # Restart the service
        tasks.restart(ctx=self._create_context('restart'))

        # Stop the service
        tasks.stop(ctx=self._create_context('stop'))

        # Uninstall, delete the files
        tasks.uninstall(ctx=self._create_context('uninstall'))

        # Assert files are gone
        self.assertFalse(runner.exists(path=RUNTIME_AGENT_PATH))
        self.assertFalse(
            runner.exists(
                path='C:\{0}'.format(AGENT_EXEC_FILE_NAME)))

    def test_create_env_string(self):

        from windows_agent_installer.tasks import create_env_string

        cloudify_agent = {
            'host': '127.0.0.1'
        }
        import os
        os.environ[
            constants.MANAGER_FILE_SERVER_BLUEPRINTS_ROOT_URL_KEY
        ] = 'url1'
        os.environ[
            constants.MANAGER_FILE_SERVER_URL_KEY
        ] = 'url2'
        os.environ[
            constants.MANAGER_REST_PORT_KEY
        ] = '80'
        env_string = create_env_string(cloudify_agent)
        expected = 'AGENT_IP=127.0.0.1 MANAGEMENT_IP=127.0.0.1 ' \
                   'MANAGER_FILE_SERVER_BLUEPRINTS_ROOT_URL=url1 ' \
                   'MANAGER_FILE_SERVER_URL=url2 MANAGER_REST_PORT=80'
        self.assertEqual(env_string, expected)
class TestTasks(unittest.TestCase):

    """
    Test cases for the worker installer functionality.
    These tests run PowerShell commands remotely on a WinRM enabled server.

    An existing server must be setup, set the 'TEST_MACHINE_IP'
    environment variable to the server IP,
    otherwise an exception will be raised.

    Note: These tests require a machine with RabbitMQ
    running for the celery worker to start properly.
    """

    @staticmethod
    def _create_context(task_name):

        cloudify_agent = {
            'user': '******',
            'password': '******'
        }

        properties = {
            'ip': os.environ[TEST_MACHINE_IP_ENV_VARIABLE],
            'cloudify_agent': cloudify_agent
        }

        return MockCloudifyContext(
            properties=properties,
            node_id='test-node-id',
            task_name=task_name
        )

    def setUp(self):

        os.environ[TEST_MACHINE_IP_ENV_VARIABLE] = '15.126.205.73'

        if TEST_MACHINE_IP_ENV_VARIABLE not in os.environ:
            raise RuntimeError('TEST_MACHINE_IP environment variable must '
                               'be set and point to an existing server with '
                               'WinRM configured properly')

        self.runner = WinRMRunner(
            session_config=WinRMRunnerTest._create_session()
        )

    def tearDown(self):
        try:
            tasks.stop(ctx=self._create_context('stop'))
        except BaseException as e:
            logger.error(e.message)
        try:
            tasks.uninstall(ctx=self._create_context('uninstall'))
        except BaseException as e:
            logger.warning(e.message)
            self.runner.delete(path=tasks.AGENT_FOLDER_NAME,
                               ignore_missing=True)
            self.runner.delete(
                path='C:\\{0}'.format(tasks.AGENT_EXEC_FILE_NAME),
                ignore_missing=True)

    def test_full_lifecycle(self):
        tasks.install(ctx=self._create_context('install'))
        tasks.start(ctx=self._create_context('start'))

        def _create_session():
            return {
                'host': os.environ[TEST_MACHINE_IP_ENV_VARIABLE],
                'user': '******',
                'password': '******'
            }

        # Retrieve registered plugins
        from windows_agent_installer.winrm_runner import WinRMRunner
        from windows_agent_installer.tasks import RUNTIME_AGENT_PATH
        from windows_agent_installer.tasks import AGENT_EXEC_FILE_NAME
        runner = WinRMRunner(session_config=_create_session())
        response = runner.run(
            '{0}\Scripts\celery.exe inspect registered'
            .format(RUNTIME_AGENT_PATH))

        # Assert agent has necessary includes
        self.assertTrue(AGENT_INCLUDES in response.std_out)

        # Restart the service
        tasks.restart(ctx=self._create_context('restart'))

        # Stop the service
        tasks.stop(ctx=self._create_context('stop'))

        # Uninstall, delete the files
        tasks.uninstall(ctx=self._create_context('uninstall'))

        # Assert files are gone
        self.assertFalse(runner.exists(path=RUNTIME_AGENT_PATH))
        self.assertFalse(
            runner.exists(
                path='C:\{0}'.format(AGENT_EXEC_FILE_NAME)))

    def test_create_env_string(self):

        from windows_agent_installer.tasks import create_env_string

        cloudify_agent = {
            'host': '127.0.0.1'
        }
        import os
        os.environ[
            constants.MANAGER_FILE_SERVER_BLUEPRINTS_ROOT_URL_KEY
        ] = 'url1'
        os.environ[
            constants.MANAGER_FILE_SERVER_URL_KEY
        ] = 'url2'
        os.environ[
            constants.MANAGER_REST_PORT_KEY
        ] = '80'
        env_string = create_env_string(cloudify_agent)
        expected = 'AGENT_IP=127.0.0.1 MANAGEMENT_IP=127.0.0.1 ' \
                   'MANAGER_FILE_SERVER_BLUEPRINTS_ROOT_URL=url1 ' \
                   'MANAGER_FILE_SERVER_URL=url2 MANAGER_REST_PORT=80'
        self.assertEqual(env_string, expected)