Ejemplo n.º 1
0
class TestDaemonFactory(BaseTest, unittest.TestCase):
    def setUp(self):
        super(TestDaemonFactory, self).setUp()
        self.daemon_name = 'test-daemon-{0}'.format(uuid.uuid4())
        self.factory = DaemonFactory(storage=get_storage_directory())
        self.daemon_params = {
            'process_management': 'init.d',
            'name': self.daemon_name,
            'queue': 'queue',
            'rest_host': '127.0.0.1',
            'broker_ip': '127.0.0.1',
            'user': '******',
            'broker_url': '127.0.0.1',
            'broker_ssl_enabled': True,
            'local_rest_cert_file': self._rest_cert_path
        }

    def test_new_initd(self):
        daemon = self.factory.new(**self.daemon_params)
        self.assertEqual(self.daemon_name, daemon.name)
        self.assertEqual('queue', daemon.queue)
        self.assertEqual('127.0.0.1', daemon.rest_host)
        self.assertEqual('user', daemon.user)
        self.assertEqual(self._rest_cert_path, daemon.local_rest_cert_file)

    def test_new_no_implementation(self):
        self.assertRaises(exceptions.DaemonNotImplementedError,
                          self.factory.new,
                          process_management='no-impl')

    def test_save_load_delete(self):

        daemon = self.factory.new(**self.daemon_params)

        self.factory.save(daemon)
        loaded = self.factory.load(self.daemon_name)
        self.assertEqual('init.d', loaded.PROCESS_MANAGEMENT)
        self.assertEqual(self.daemon_name, loaded.name)
        self.assertEqual('queue', loaded.queue)
        self.assertEqual('127.0.0.1', loaded.rest_host)
        self.assertEqual('user', loaded.user)
        self.factory.delete(daemon.name)
        self.assertRaises(exceptions.DaemonNotFoundError, self.factory.load,
                          daemon.name)

    def test_load_non_existing(self):
        self.assertRaises(exceptions.DaemonNotFoundError, self.factory.load,
                          'non_existing_name')

    def test_load_all(self):
        def _save_daemon(name):
            params = self.daemon_params.copy()
            params['name'] = name
            daemon = self.factory.new(**params)
            self.factory.save(daemon)

        if os.path.exists(get_storage_directory()):
            shutil.rmtree(get_storage_directory())

        daemons = self.factory.load_all()
        self.assertEquals(0, len(daemons))
        _save_daemon(utils.internal.generate_agent_name())
        _save_daemon(utils.internal.generate_agent_name())
        _save_daemon(utils.internal.generate_agent_name())

        daemons = self.factory.load_all()
        self.assertEquals(3, len(daemons))

    def test_new_existing_agent(self):
        daemon = self.factory.new(**self.daemon_params)

        self.factory.save(daemon)

        # without no_overwrite, this will overwrite the existing daemon
        daemon = self.factory.new(**self.daemon_params)

        self.assertRaises(exceptions.DaemonAlreadyExistsError,
                          self.factory.new,
                          no_overwrite=True,
                          **self.daemon_params)
Ejemplo n.º 2
0
class TestDaemonFactory(BaseShellTest):

    def setUp(self):
        super(TestDaemonFactory, self).setUp()
        self.daemon_name = 'test-daemon-{0}'.format(uuid.uuid4())
        self.factory = DaemonFactory(storage=get_storage_directory())

    def test_new_initd(self):
        daemon = self.factory.new(
            process_management='init.d',
            name=self.daemon_name,
            queue='queue',
            rest_host='127.0.0.1',
            broker_ip='127.0.0.1',
            file_server_host='127.0.0.1',
            user='******',
            broker_url='127.0.0.1')
        self.assertEqual(self.daemon_name, daemon.name)
        self.assertEqual('queue', daemon.queue)
        self.assertEqual('127.0.0.1', daemon.rest_host)
        self.assertEqual('amqp://*****:*****@127.0.0.1:5672//',
                         daemon.broker_url)
        self.assertEqual('user', daemon.user)

    def test_new_no_implementation(self):
        self.assertRaises(exceptions.DaemonNotImplementedError,
                          self.factory.new,
                          process_management='no-impl')

    def test_save_load_delete(self):

        daemon = self.factory.new(
            process_management='init.d',
            name=self.daemon_name,
            queue='queue',
            rest_host='127.0.0.1',
            broker_ip='127.0.0.1',
            file_server_host='127.0.0.1',
            user='******',
            broker_url='127.0.0.1')

        self.factory.save(daemon)
        loaded = self.factory.load(self.daemon_name)
        self.assertEqual('init.d', loaded.PROCESS_MANAGEMENT)
        self.assertEqual(self.daemon_name, loaded.name)
        self.assertEqual('queue', loaded.queue)
        self.assertEqual('127.0.0.1', loaded.rest_host)
        self.assertEqual('user', loaded.user)
        self.assertEqual('amqp://*****:*****@127.0.0.1:5672//',
                         daemon.broker_url)
        self.factory.delete(daemon.name)
        self.assertRaises(exceptions.DaemonNotFoundError,
                          self.factory.load, daemon.name)

    def test_load_non_existing(self):
        self.assertRaises(exceptions.DaemonNotFoundError,
                          self.factory.load,
                          'non_existing_name')

    def test_load_all(self):

        def _save_daemon(name):
            daemon = self.factory.new(
                process_management='init.d',
                name=name,
                queue='queue',
                rest_host='127.0.0.1',
                broker_ip='127.0.0.1',
                file_server_host='127.0.0.1',
                user='******',
                broker_url='127.0.0.1')
            self.factory.save(daemon)

        if os.path.exists(get_storage_directory()):
            shutil.rmtree(get_storage_directory())

        daemons = self.factory.load_all()
        self.assertEquals(0, len(daemons))

        _save_daemon(utils.internal.generate_agent_name())
        _save_daemon(utils.internal.generate_agent_name())
        _save_daemon(utils.internal.generate_agent_name())

        daemons = self.factory.load_all()
        self.assertEquals(3, len(daemons))

    def test_new_existing_agent(self):

        daemon = self.factory.new(
            process_management='init.d',
            name=self.daemon_name,
            queue='queue',
            rest_host='127.0.0.1',
            broker_ip='127.0.0.1',
            file_server_host='127.0.0.1',
            user='******',
            broker_url='127.0.0.1')

        self.factory.save(daemon)

        self.assertRaises(exceptions.DaemonAlreadyExistsError,
                          self.factory.new,
                          process_management='init.d',
                          name=self.daemon_name,
                          queue='queue',
                          rest_host='127.0.0.1',
                          broker_ip='127.0.0.1',
                          file_server_host='127.0.0.1',
                          user='******',
                          broker_url='127.0.0.1')
Ejemplo n.º 3
0
class TestDaemonFactory(BaseShellTest):
    def setUp(self):
        super(TestDaemonFactory, self).setUp()
        self.daemon_name = 'test-daemon-{0}'.format(uuid.uuid4())
        self.factory = DaemonFactory(storage=get_storage_directory())

    def test_new_initd(self):
        daemon = self.factory.new(process_management='init.d',
                                  name=self.daemon_name,
                                  queue='queue',
                                  manager_ip='127.0.0.1',
                                  user='******',
                                  broker_url='127.0.0.1')
        self.assertEqual(self.daemon_name, daemon.name)
        self.assertEqual('queue', daemon.queue)
        self.assertEqual('127.0.0.1', daemon.manager_ip)
        self.assertEqual('amqp://*****:*****@127.0.0.1:5672//',
                         daemon.broker_url)
        self.assertEqual('user', daemon.user)

    def test_new_wrong_includes_attribute(self):
        self.assertRaises(ValueError,
                          self.factory.new,
                          process_management='init.d',
                          queue='{0}-queue'.format(self.daemon_name),
                          name=self.daemon_name,
                          manager_ip='127.0.0.1',
                          includes=set(['plugin']))

    def test_new_no_implementation(self):
        self.assertRaises(exceptions.DaemonNotImplementedError,
                          self.factory.new,
                          process_management='no-impl')

    def test_save_load_delete(self):

        daemon = self.factory.new(process_management='init.d',
                                  name=self.daemon_name,
                                  queue='queue',
                                  manager_ip='127.0.0.1',
                                  user='******',
                                  broker_url='127.0.0.1')

        self.factory.save(daemon)
        loaded = self.factory.load(self.daemon_name)
        self.assertEqual('init.d', loaded.PROCESS_MANAGEMENT)
        self.assertEqual(self.daemon_name, loaded.name)
        self.assertEqual('queue', loaded.queue)
        self.assertEqual('127.0.0.1', loaded.manager_ip)
        self.assertEqual('user', loaded.user)
        self.assertEqual('amqp://*****:*****@127.0.0.1:5672//',
                         daemon.broker_url)
        self.factory.delete(daemon.name)
        self.assertRaises(exceptions.DaemonNotFoundError, self.factory.load,
                          daemon.name)

    def test_load_non_existing(self):
        self.assertRaises(exceptions.DaemonNotFoundError, self.factory.load,
                          'non_existing_name')

    def test_load_all(self):
        def _save_daemon(name):
            daemon = self.factory.new(process_management='init.d',
                                      name=name,
                                      queue='queue',
                                      manager_ip='127.0.0.1',
                                      user='******',
                                      broker_url='127.0.0.1')
            self.factory.save(daemon)

        if os.path.exists(get_storage_directory()):
            shutil.rmtree(get_storage_directory())

        daemons = self.factory.load_all()
        self.assertEquals(0, len(daemons))

        _save_daemon(utils.internal.generate_agent_name())
        _save_daemon(utils.internal.generate_agent_name())
        _save_daemon(utils.internal.generate_agent_name())

        daemons = self.factory.load_all()
        self.assertEquals(3, len(daemons))

    def test_new_existing_agent(self):

        daemon = self.factory.new(process_management='init.d',
                                  name=self.daemon_name,
                                  queue='queue',
                                  manager_ip='127.0.0.1',
                                  user='******',
                                  broker_url='127.0.0.1')

        self.factory.save(daemon)

        self.assertRaises(exceptions.DaemonAlreadyExistsError,
                          self.factory.new,
                          process_management='init.d',
                          name=self.daemon_name,
                          queue='queue',
                          manager_ip='127.0.0.1',
                          user='******',
                          broker_url='127.0.0.1')
Ejemplo n.º 4
0
class TestDaemonFactory(BaseTest, unittest.TestCase):

    def setUp(self):
        super(TestDaemonFactory, self).setUp()
        self.daemon_name = 'test-daemon-{0}'.format(uuid.uuid4())
        self.factory = DaemonFactory(storage=get_storage_directory())
        self.daemon_params = {
            'process_management': 'init.d',
            'name': self.daemon_name,
            'queue': 'queue',
            'rest_host': '127.0.0.1',
            'broker_ip': '127.0.0.1',
            'user': '******',
            'broker_url': '127.0.0.1',
            'broker_ssl_enabled': True,
            'local_rest_cert_file': self._rest_cert_path
        }

    def test_new_initd(self):
        daemon = self.factory.new(**self.daemon_params)
        self.assertEqual(self.daemon_name, daemon.name)
        self.assertEqual('queue', daemon.queue)
        self.assertEqual('127.0.0.1', daemon.rest_host)
        self.assertEqual('user', daemon.user)
        self.assertEqual(self._rest_cert_path,
                         daemon.local_rest_cert_file)

    def test_new_no_implementation(self):
        self.assertRaises(exceptions.DaemonNotImplementedError,
                          self.factory.new,
                          process_management='no-impl')

    def test_save_load_delete(self):

        daemon = self.factory.new(**self.daemon_params)

        self.factory.save(daemon)
        loaded = self.factory.load(self.daemon_name)
        self.assertEqual('init.d', loaded.PROCESS_MANAGEMENT)
        self.assertEqual(self.daemon_name, loaded.name)
        self.assertEqual('queue', loaded.queue)
        self.assertEqual('127.0.0.1', loaded.rest_host)
        self.assertEqual('user', loaded.user)
        self.factory.delete(daemon.name)
        self.assertRaises(exceptions.DaemonNotFoundError,
                          self.factory.load, daemon.name)

    def test_load_non_existing(self):
        self.assertRaises(exceptions.DaemonNotFoundError,
                          self.factory.load,
                          'non_existing_name')

    def test_load_all(self):

        def _save_daemon(name):
            params = self.daemon_params.copy()
            params['name'] = name
            daemon = self.factory.new(**params)
            self.factory.save(daemon)

        if os.path.exists(get_storage_directory()):
            shutil.rmtree(get_storage_directory())

        daemons = self.factory.load_all()
        self.assertEquals(0, len(daemons))
        _save_daemon(utils.internal.generate_agent_name())
        _save_daemon(utils.internal.generate_agent_name())
        _save_daemon(utils.internal.generate_agent_name())

        daemons = self.factory.load_all()
        self.assertEquals(3, len(daemons))

    def test_new_existing_agent(self):
        daemon = self.factory.new(**self.daemon_params)

        self.factory.save(daemon)

        # without no_overwrite, this will overwrite the existing daemon
        daemon = self.factory.new(**self.daemon_params)

        self.assertRaises(exceptions.DaemonAlreadyExistsError,
                          self.factory.new,
                          no_overwrite=True,
                          **self.daemon_params)