Package tlib :: Package base :: Module SearchEngineLoader |
[hide private]
[frames] | no frames]

# Source Code for Module tlib.base.SearchEngineLoader

     1  from fabric.state import env
     2  from fabric.operations import run, put
     3  import pytest
     4
     5
     6 -class SearchEngineLoader(object):
     7
     8 -    class OperationError(Exception):
     9          pass
    10
    11 -    def __init__(self, host, username, key):
    12          """
    13          Created an instance of this object
    14          @param host: IP address of host of server to connect
    15          @type host: str
    16          @param username: Username used to connect
    17          @type username: str
    18          @param key: Path to the ssh key used for authentication
    19          @type key: str
    20          """
    21          super(SearchEngineLoader, self).__init__()
    22          env.host_string = host
    23          env.user = username
    24          env.key_filename = key
    25
    26          # Dont' exit app when there is an error
    27          def raise_error(msg):
    28              raise self.OperationError(msg)
    29
    30          env.abort_exception = lambda msg: raise_error(msg)
    31
    32 -    def load_xmlgen(self, xmlfile, logger):
    33          """
    34          Loads a xmlgen file to the server and starts a re-index of the search engine
    35          @param xmlfile: XML text to load on the search engine
    36          @type xmlfile: str
    37          """
    38          try:
    39              env.shell_env = {"PROJECT_DIR": '/mnt/solr/indexer',
    40                               "DATA_DIR": "/mnt/solr/datafeed"}
    41
    42              # Upload xmlgen file
    43              logger.debug("Uploading file %s" % xmlfile)
    44              put(xmlfile,
    45                  r"/mnt/solr/datafeed/MainSystem/ypse.ypca.140218.2252.0.xml")
    46
    47              #Start re-index
    48              logger.debug("Start re-index of search engine")
    49              run('${PROJECT_DIR}/bin/execute_merchant.sh ${PROJECT_DIR} ${DATA_DIR}', shell=True)
    50          except self.OperationError as e:
    51              logger.error("Error uploading xmlgen file:\\n%s" % e.message)
    52              pytest.fail("Error uploading xmlgen file:\\n%s" % e.message)
    53