예제 #1
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_set_file(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        my_service = ServiceManager.get(SERVICE_ONE)
        node_one = session.add_node()
        node_two = session.add_node()
        file_name = my_service.configs[0]
        file_data_one = "# custom file one"
        file_data_two = "# custom file two"
        session.services.set_service_file(node_one.objid, my_service.name, file_name, file_data_one)
        session.services.set_service_file(node_two.objid, my_service.name, file_name, file_data_two)

        # when
        custom_service_one = session.services.get_service(node_one.objid, my_service.name)
        session.services.create_service_files(node_one, custom_service_one)
        custom_service_two = session.services.get_service(node_two.objid, my_service.name)
        session.services.create_service_files(node_two, custom_service_two)

        # then
        file_path_one = node_one.hostfilename(file_name)
        assert os.path.exists(file_path_one)
        with open(file_path_one, "r") as custom_file:
            assert custom_file.read() == file_data_one

        file_path_two = node_two.hostfilename(file_name)
        assert os.path.exists(file_path_two)
        with open(file_path_two, "r") as custom_file:
            assert custom_file.read() == file_data_two
예제 #2
0
def load():
    """
    Loads all services from the modules that reside under core.services.

    :return: nothing
    """
    ServiceManager.add_services(_PATH)
예제 #3
0
파일: test_services.py 프로젝트: yrs1/core
 def test_service_import(self):
     """
     Test importing a custom service.
     """
     ServiceManager.add_services(_SERVICES_PATH)
     assert ServiceManager.get(SERVICE_ONE)
     assert ServiceManager.get(SERVICE_TWO)
예제 #4
0
    def test_import_service(self):
        """
        Test importing a custom service.

        :param conftest.Core core: core fixture to test with
        """
        ServiceManager.add_services(_SERVICES_PATH)
        assert ServiceManager.get("MyService")
        assert ServiceManager.get("MyService2")
예제 #5
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_add_services(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        node = session.add_node()
        total_service = len(node.services)

        # when
        session.services.add_services(node, node.type, [SERVICE_ONE, SERVICE_TWO])

        # then
        assert node.services
        assert len(node.services) == total_service + 2
예제 #6
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_stop_error(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        my_service = ServiceManager.get(SERVICE_TWO)
        node = session.add_node()
        session.services.create_service_files(node, my_service)

        # when
        status = session.services.stop_service(node, my_service)

        # then
        assert status
예제 #7
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_startup(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        my_service = ServiceManager.get(SERVICE_ONE)
        node = session.add_node()
        session.services.create_service_files(node, my_service)

        # when
        status = session.services.startup_service(node, my_service, wait=True)

        # then
        assert not status
예제 #8
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_file(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        my_service = ServiceManager.get(SERVICE_ONE)
        node = session.add_node()
        file_name = my_service.configs[0]
        file_path = node.hostfilename(file_name)

        # when
        session.services.create_service_files(node, my_service)

        # then
        assert os.path.exists(file_path)
예제 #9
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_all_configs(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        node = session.add_node()

        # when
        session.services.set_service(node.objid, SERVICE_ONE)
        session.services.set_service(node.objid, SERVICE_TWO)

        # then
        all_configs = session.services.all_configs()
        assert all_configs
        assert len(all_configs) == 2
예제 #10
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_custom_startup(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        my_service = ServiceManager.get(SERVICE_ONE)
        node = session.add_node()

        # when
        session.services.set_service(node.objid, my_service.name)
        custom_my_service = session.services.get_service(node.objid, my_service.name)
        custom_my_service.startup = ("sh custom.sh",)

        # then
        assert my_service.startup != custom_my_service.startup
예제 #11
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_all_files(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        file_name = "myservice.sh"
        node = session.add_node()

        # when
        session.services.set_service_file(node.objid, SERVICE_ONE, file_name, "# test")

        # then
        service = session.services.get_service(node.objid, SERVICE_ONE)
        all_files = session.services.all_files(service)
        assert service
        assert all_files and len(all_files) == 1
예제 #12
0
파일: test_services.py 프로젝트: yrs1/core
    def test_service_setget(self, session):
        # given
        ServiceManager.add_services(_SERVICES_PATH)
        my_service = ServiceManager.get(SERVICE_ONE)
        node = session.add_node()

        # when
        no_service = session.services.get_service(node.objid, SERVICE_ONE)
        default_service = session.services.get_service(node.objid, SERVICE_ONE, default_service=True)
        session.services.set_service(node.objid, SERVICE_ONE)
        custom_service = session.services.get_service(node.objid, SERVICE_ONE, default_service=True)

        # then
        assert no_service is None
        assert default_service == my_service
        assert custom_service and custom_service != my_service
예제 #13
0
def load():
    """
    Loads all services from the modules that reside under core.services.

    :return: list of services that failed to load
    :rtype: list[str]
    """
    return ServiceManager.add_services(_PATH)
예제 #14
0
def create_session(topo_path, _id, dtn_software):
    coreemu = CoreEmu()
    session = coreemu.create_session(_id=_id)
    session.set_state(EventTypes.CONFIGURATION_STATE)

    ServiceManager.add_services('/root/.core/myservices')

    session.open_xml(topo_path)

    for obj in session.objects.itervalues():
        if type(obj) is CoreNode:
            session.services.add_services(obj, obj.type,
                                          ['pidstat', 'bwm-ng', dtn_software])

    session.instantiate()

    return session
예제 #15
0
파일: coreemu.py 프로젝트: fno2010/core
    def load_services(self):
        # load default services
        self.service_errors = core.services.load()

        # load custom services
        service_paths = self.config.get("custom_services_dir")
        logger.debug("custom service paths: %s", service_paths)
        if service_paths:
            for service_path in service_paths.split(','):
                service_path = service_path.strip()
                custom_service_errors = ServiceManager.add_services(service_path)
                self.service_errors.extend(custom_service_errors)