Пример #1
0
    def stop(self, instance_name, padded=False):
        if not padded:
            progress_log('Stopping instance')

        process_name = self.process_name(instance_name)
        supervisor = SupervisorControl(self.config)

        supervisor.stop(process_name)

        padded_log('Waiting for "{}" instance to stop...'.format(instance_name))

        retries = 10
        status = self.get_status(instance_name)

        while retries > 0 or status['status'] != 'stopped':
            sleep(0.5)
            status = self.get_status(instance_name)
            retries -= 1

        status = self.get_status(instance_name)
        if status['status'].lower() == 'stopped':
            padded_success('Instance "{}" stopped'.format(instance_name))
            return True
        else:
            padded_error('Instance "{}" still active'.format(instance_name))
            return False
Пример #2
0
    def start(self, instance_name, padded=False):
        if not padded:
            progress_log('Starting instance')
        status = self.get_status(instance_name)

        process_name = self.process_name(instance_name)
        supervisor = SupervisorControl(self.config)

        if status['status'] == 'unknown':
            padded_log('Unknown {} status ...')
        elif status['status'] == 'not found':
            supervisor.load(process_name)
        else:
            padded_log('Process stopped, starting ...')
            supervisor.start(process_name)

        padded_log('Waiting for process "{}" to start...'.format(process_name))

        retries = 10
        status = self.get_status(instance_name)

        while retries > 0 or status['status'] != 'running':
            sleep(0.5)
            status = self.get_status(instance_name)
            retries -= 1

        if status['status'] == 'running':
            padded_success('Process "{}" started'.format(process_name))
            return True
        elif status['status'] in ['fatal', 'backoff']:
            padded_error('Process "{}" not started, an error occurred'.format(process_name))
            return False
        else:
            padded_error('Process "{}" not started'.format(process_name))
            return False
Пример #3
0
    def restart(self, instance_name):
        progress_log('Restarting instance')

        stop_result = self.stop(instance_name, padded=True)
        if stop_result is True:
            start_result = self.start(instance_name, padded=True)

        if start_result is True:
            padded_log('Instance "{}" restarted'.format(instance_name))
        else:
            padded_error('Instance "{}" not restarted'.format(instance_name))
Пример #4
0
    def reload_nginx_configuration(self):
        progress_log("Reloading nginx configuration")
        padded_log("Testing configuration")
        code, stdout = self.prefes.execute("/etc/init.d/nginx configtest")
        if code == 0 and "done" in stdout:
            padded_success("Configuration test passed")
        else:
            padded_error("Configuration test failed")
            return None

        code, stdout = self.prefes.execute("/etc/init.d/nginx reload")
        if code == 0 and "done" in stdout:
            padded_success("Nginx reloaded succesfully")
        else:
            padded_error("Error reloading nginx")
            return None
Пример #5
0
    def test_activity(self, instance_name, ldap_branch, restricted_user_password):

        progress_log('Testing UTalk activity notifications')

        # Get a maxclient for this instance
        padded_log("Getting instance information")
        instance_info = self.get_instance(instance_name)
        restricted_password = restricted_user_password
        client = self.get_client(instance_name, username='******', password=restricted_password)

        padded_log("Setting up test clients")
        test_users = [
            ('ulearn.testuser1', 'UTestuser1'),
            ('ulearn.testuser2', 'UTestuser2')
        ]

        utalk_clients = []
        max_clients = []

        # Syncronization primitives
        wait_for_others = AsyncResult()
        counter = ReadyCounter(wait_for_others)

        for user, password in test_users:
            max_clients.append(self.get_client(
                instance_name,
                username=user,
                password=password)
            )

            # Create websocket clients
            utalk_clients.append(getUtalkClient(
                instance_info['server']['dns'],
                instance_name,
                user,
                password,
                quiet=False
            ))
            counter.add()

        # Create users
        padded_log("Creating users and conversations")
        client.people['ulearn.testuser1'].post()
        client.people['ulearn.testuser2'].post()

        # Admin creates context with notifications enabled and subscribes users to it
        context = client.contexts.post(url='http://testcontext', displayName='Test Context', notifications=True)
        client.people['ulearn.testuser1'].subscriptions.post(object_url='http://testcontext')
        client.people['ulearn.testuser2'].subscriptions.post(object_url='http://testcontext')

        def post_activity():
            max_clients[0].people['ulearn.testuser1'].activities.post(
                object_content='Hola',
                contexts=[{"url": "http://testcontext", "objectType": "context"}]
            )

        # Prepare test messages for clients
        # First argument are messages to send (conversation, message)
        # Second argument are messages to expect (conversation, sender, message)
        # Third argument is a syncronization event to wait for all clients to be listening
        # Fourth argument is a method to trigger when client ready

        arguments1 = [
            [

            ],
            [
                ('test', 'test')
            ],
            counter,
            post_activity
        ]

        arguments2 = [
            [

            ],
            [
                ('test', 'test')
            ],
            counter,
            None
        ]

        padded_log("Starting websockets and waiting for messages . . .")

        greenlets = [
            gevent.spawn(utalk_clients[0].test, *arguments1),
            gevent.spawn(utalk_clients[1].test, *arguments2)
        ]

        gevent.joinall(greenlets, timeout=20, raise_error=True)

        success = None not in [g.value for g in greenlets]

        if success:
            padded_success('Websocket test passed')
        else:
            padded_error('Websocket test failed, Timed out')
Пример #6
0
    def test(self, domain, restricted_password):
        progress_log('Testing UTalk websocket communication')

        # Get a maxclient for this instance
        padded_log("Getting instance information")

        domain_info = self.getDomainInfo(domain)
        client = self.config.max.get_client(domain, username='******', password=restricted_password)

        padded_log("Setting up test clients")
        test_users = [
            ('ulearn.testuser1', 'UTestuser1'),
            ('ulearn.testuser2', 'UTestuser2')
        ]

        utalk_clients = []
        max_clients = []

        # Syncronization primitives
        wait_for_others = AsyncResult()
        counter = ReadyCounter(wait_for_others)

        for user, password in test_users:
            max_clients.append(self.config.max.get_client(
                domain,
                username=user,
                password=password)
            )

            # Create websocket clients
            utalk_clients.append(self.getUtalkClient(
                domain_info['max']['server']['dns'],
                user,
                password,
                quiet=True
            ))
            counter.add()

        # Create users
        padded_log("Creating users and conversations")
        client.people['ulearn.testuser1'].post()
        client.people['ulearn.testuser2'].post()

        # user 1 creates conversation with user 2
        conversation = max_clients[0].conversations.post(
            contexts=[{"objectType": "conversation", "participants": [test_users[0][0], test_users[1][0]]}],
            object_content='Initial message'
        )
        conversation_id = conversation['contexts'][0]['id']

        # Prepare test messages for clients
        # First argument are messages to send (conversation, message)
        # Second argument are messages to expect (conversation, sender, message)
        # Third argument is a syncronization event to wait for all clients to be listening

        arguments1 = [
            [
                (conversation_id, 'First message from 1'),
                (conversation_id, 'Second message from 1')
            ],
            [
                (conversation_id, test_users[1][0], 'First message from 2'),
                (conversation_id, test_users[1][0], 'Second message from 2')
            ],
            counter,
        ]

        arguments2 = [
            [
                (conversation_id, 'First message from 2'),
                (conversation_id, 'Second message from 2')
            ],
            [
                (conversation_id, test_users[0][0], 'First message from 1'),
                (conversation_id, test_users[0][0], 'Second message from 1')
            ],
            counter
        ]

        padded_log("Starting websockets and waiting for messages . . .")

        utalk_clients[0].setup(*arguments1)
        utalk_clients[1].setup(*arguments2)

        greenlets = [
            gevent.spawn(utalk_clients[0].connect),
            gevent.spawn(utalk_clients[1].connect)
        ]

        gevent.joinall(greenlets, timeout=60, raise_error=True)
        success = None not in [g.value for g in greenlets]

        utalk_clients[0].teardown()
        utalk_clients[1].teardown()

        # Cleanup
        max_clients[0].conversations[conversation_id].delete()

        #client.people['ulearn.testuser1'].delete()
        #client.people['ulearn.testuser2'].delete()

        if success:
            padded_success('Websocket test passed')
        else:
            padded_error('Websocket test failed, Timed out')