Example #1
0
def main():
    # Disable logger that ships with marathon package
    marathon_logger.disabled = True

    module = AnsibleModule(argument_spec=dict(
        args=dict(default=None, type="list"),
        cpus=dict(default=1.0, type="float"),
        command=dict(default=None, type="str"),
        constraints=dict(default=None, type="list"),
        container=dict(default=None, type="dict"),
        env=dict(default=dict(), type="dict"),
        host=dict(default="http://localhost:8080", type="str"),
        instances=dict(default=1, type="int"),
        memory=dict(default=256.0, type="float"),
        name=dict(required=True, type="str"),
        state=dict(default="present",
                   choices=["absent", "present"],
                   type="str"),
        wait=dict(default="yes", choices=BOOLEANS, type="bool"),
        wait_timeout=dict(default=300, type="int")),
                           mutually_exclusive=(["args", "cmd"], ))

    if HAS_MARATHON_PACKAGE is False:
        module.fail_json(
            "The Ansible Marathon App module requires `marathon` >= 0.6.3")

    try:
        marathon_client = MarathonClient(module.params['host'])

        marathon = Marathon(client=marathon_client, module=module)

        marathon.sync()
    except (MarathonError, TimeoutError), e:
        module.fail_json(msg=str(e))
Example #2
0
def _run(func,
         servers=None,
         username=None,
         password=None,
         timeout=10,
         *args,
         **kwargs):
    """
    Wrapper function for MarathonClient
    """
    func_args = args
    func_kwargs = kwargs

    kwargs = {
        'servers': servers or __salt__['config.option']('marathon.servers'),
        'username': username or __salt__['config.option']('marathon.username'),
        'password': password or __salt__['config.option']('marathon.password'),
        'timeout': timeout,
    }

    try:
        client = MarathonClient(**kwargs)
        getattr(client, func)(*func_args, **func_kwargs)  # pylint: disable=W0142
    except MarathonError:
        raise
Example #3
0
class TestEventSubscription(unittest.TestCase):
    """
    This test will generate an event from Marathon's EventBus and then test the creation of a Marathon EventObject.
    It will spawn a separate server process for capturing Marathon Callbacks.
    """

    def setUp(self):
        self.app = get_app()
        self.factory = EventFactory()
        self.client = MarathonClient(servers=[MARATHON_SERVER])
        self.client.create_event_subscription(url=MARATHON_CALLBACK_URL)

    def test_event_factory(self):
        queue = Queue()  # Use a Multiprocess Queue for communication with subprocess.
        receive = Process(target=listen_for_events, args=[queue])
        receive.start()  # Start the server.
        self.client.create_event_subscription(url='192.0.2.1')  # Generate an event (subscribe_event).
        while True:
            o = self.factory.process(queue.get(timeout=120))  # Raise queueEmpty if the test exceeds 2 minutes.
            if isinstance(o, MarathonSubscribeEvent):
                print(o, dir(o), o.__dict__)
                self.assertEqual(o.event_type, 'subscribe_event')
                break
        receive.terminate()

    def tearDown(self):
        self.client.delete_event_subscription(url='192.0.2.1')
Example #4
0
 def setUp(self):
     self.app = get_app()
     self.factory = EventFactory()
     self.client = MarathonClient(servers=[MARATHON_SERVER])
     self.client.create_event_subscription(url=MARATHON_CALLBACK_URL)