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