def delete_database_in_mongo(context): """ Delete database used in mongo """ fiware_service_header = u'Fiware-Service' orion_prefix = u'orion' global cb properties_class = Properties() props_mongo = properties_class.read_properties()[ "mongo_env"] # mongo properties dict m = Mongo(host=props_mongo["MONGO_HOST"], port=props_mongo["MONGO_PORT"], user=props_mongo["MONGO_USER"], password=props_mongo["MONGO_PASS"]) headers = cb.get_headers() if fiware_service_header in headers and ( headers[fiware_service_header].find(".") < 0): __logger__.debug("Deleting database in mongo...") if fiware_service_header in headers: database_name = "%s-%s" % (orion_prefix, headers[fiware_service_header]) else: database_name = orion_prefix m.connect(database_name.lower()) m.drop_database() m.disconnect() __logger__.debug("...Database \"%s\" is deleted" % database_name.lower())
def initial_conf(file_name, sudo_run, drop_all_databases): """ define initial config simulate background in lettuce :param file_name: :param sudo_run: :param drop_all_databases: """ print colored(" Background: in terrain...", 'white', 'on_grey', attrs=['bold']) print colored(" Given starting the configuration from terrain...", 'green', 'on_grey', attrs=['bold']) properties = Properties (file=file_name, sudo=sudo_run) print colored(" And updating properties.json from %s" % file_name, 'green', 'on_grey', attrs=['bold']) properties.read_properties() print colored(" And reading properties", 'green', 'on_grey', attrs=['bold']) properties.storing_dictionaries() print colored(" And creating instances to sth and mongo with properties", 'green', 'on_grey', attrs=['bold']) # The next line is commented because at the moment the rpm package does not exists. STH is executed manually #world.sth.sth_service("restart") #print colored(" And restarting sth service", 'green', 'on_grey', attrs=['bold']) world.sth.verify_sth_version() print colored(" And verifying sth version", 'green', 'on_grey', attrs=['bold']) world.sth.verify_mongo_version() print colored(" And verifying mongo version", 'green', 'on_grey', attrs=['bold']) if drop_all_databases: world.sth.drop_all_test_databases() print colored(" And drop all tests databases with prefix: sth_test", 'green', 'on_grey', attrs=['bold']) print colored(" Then completed the configuration from terrain...", 'green', 'on_grey', attrs=['bold'])
def service_and_service_path(context): """ configuration of service an service path in headers :param context: """ global cb properties_class = Properties() props = properties_class.read_properties()[CONTEXT_BROKER_ENV] cb = CB(protocol=props["CB_PROTOCOL"], host=props["CB_HOST"], port=props["CB_PORT"]) cb.definition_headers(context)
def copy_properties_file_from_and_sudo(step, file_name, sudo_run): """ copy properties.json specific to feature from setting folder, read properties and create necessaries class :param step: :param file_name: file name of configuration associated at features, stored in settings folder :param sudo_run: with superuser privileges (True | False) """ if not world.background_executed: properties = Properties (file=file_name, sudo=sudo_run) properties.read_properties() properties.storing_dictionaries()
def update_properties_file(context, properties_file, sudo_run): """ update properties.py file from setting folder or jenkins console :param context: :param properties_file: file to get data to update properties.py """ global properties_class __logger__.info(" >> config file used: '%s'", properties_file) properties_class = Properties() properties_class.update_properties_json_file(properties_file, sudo_run) __logger__.info(" >> properties.json is updated")
def send_a_statistics_request(context): """ send a statistics request :param context: """ global cb, resp, props_cb_env __logger__.debug("Sending a statistics request...") properties_class = Properties() props_cb_env = properties_class.read_properties()[CONTEXT_BROKER_ENV] cb = CB(protocol=props_cb_env["CB_PROTOCOL"], host=props_cb_env["CB_HOST"], port=props_cb_env["CB_PORT"]) resp = cb.get_statistics_request() __logger__.info("..Sent a statistics request correctly")
def send_a_base_request(context): """ send a API entry point request :param context: """ global cb, resp __logger__.debug("Sending a API entry point request: /v2 ...") properties_class = Properties() props = properties_class.read_properties()[CONTEXT_BROKER_ENV] cb = CB(protocol=props["CB_PROTOCOL"], host=props["CB_HOST"], port=props["CB_PORT"]) resp = cb.get_base_request() __logger__.info("...Sent a API entry point request: /v2 correctly")
def entities_are_not_stored_in_mongo(context): """ verify that entities are not stored in mongo """ global cb properties_class = Properties() props_mongo = properties_class.read_properties()["mongo_env"] # mongo properties dict __logger__.debug(" >> verifying entities are not stored in mongo") m = Mongo(host=props_mongo["MONGO_HOST"], port=props_mongo["MONGO_PORT"], user=props_mongo["MONGO_USER"], password=props_mongo["MONGO_PASS"]) ngsi = NGSI() ngsi.verify_entities_stored_in_mongo(m, cb.get_entity_context(), cb.get_headers(), False) __logger__.info(" >> verified entities are not stored in mongo")
def copy_properties_json_file_to_test_from_setting_and_sudo_local (step, file_name, sink, sudo_run): """ copy properties.json specific to feature from setting folder, read properties and create necessaries class :param step: :param file_name: file name of configuration associated at features, stored in settings folder :param sink: sink used in each feature (ckan-sink |mysql-sink | hdfs-sink) :param sudo_run: with superuser privileges (True | False) """ if not world.background_executed: world.sink = sink properties = Properties (file=file_name, sudo=sudo_run) properties.read_properties() properties.storing_dictionaries(sink)
def entities_are_not_stored_in_mongo(context): """ verify that entities are not stored in mongo """ global cb properties_class = Properties() props_mongo = properties_class.read_properties()[ "mongo_env"] # mongo properties dict __logger__.debug(" >> verifying entities are not stored in mongo") m = Mongo(host=props_mongo["MONGO_HOST"], port=props_mongo["MONGO_PORT"], user=props_mongo["MONGO_USER"], password=props_mongo["MONGO_PASS"]) ngsi = NGSI() ngsi.verify_entities_stored_in_mongo(m, cb.get_entity_context(), cb.get_headers(), False) __logger__.info(" >> verified entities are not stored in mongo")
def initial_conf(file_name, sudo_run): """ define initial config simulate background in lettuce :param file_name: :param sudo_run: """ print colored(" Background: in terrain...", 'white', 'on_grey', attrs=['bold']) print colored(" Given starting the configuration from terrain...", 'green', 'on_grey', attrs=['bold']) properties = Properties(file=file_name, sudo=sudo_run) print colored(" And updating properties.json from %s" % file_name, 'green', 'on_grey', attrs=['bold']) properties.read_properties() print colored(" And reading properties", 'green', 'on_grey', attrs=['bold']) properties.storing_dictionaries() print colored( " And creating instances to sth and mongo with properties", 'green', 'on_grey', attrs=['bold']) world.sth.sth_service("restart") print colored(" And restarting sth service", 'green', 'on_grey', attrs=['bold']) world.sth.verify_sth_version() print colored(" And verifying sth version", 'green', 'on_grey', attrs=['bold']) world.sth.verify_mongo_version() print colored(" And verifying mongo version", 'green', 'on_grey', attrs=['bold']) if properties.get_drop_all_databases().lower().find("true") >= 0: world.sth.drop_all_test_databases() print colored(" And drop all tests databases with prefix: sth_test", 'green', 'on_grey', attrs=['bold']) print colored(" Then completed the configuration from terrain...", 'green', 'on_grey', attrs=['bold'])
def delete_database_in_mongo(context): """ Delete database used in mongo """ fiware_service_header = u'Fiware-Service' orion_prefix = u'orion' global cb properties_class = Properties() props_mongo = properties_class.read_properties()["mongo_env"] # mongo properties dict m = Mongo(host=props_mongo["MONGO_HOST"], port=props_mongo["MONGO_PORT"], user=props_mongo["MONGO_USER"], password=props_mongo["MONGO_PASS"]) headers = cb.get_headers() if fiware_service_header in headers and (headers[fiware_service_header].find(".") < 0): __logger__.debug("Deleting database in mongo...") if fiware_service_header in headers: database_name = "%s-%s" % (orion_prefix, headers[fiware_service_header]) else: database_name = orion_prefix m.connect(database_name.lower()) m.drop_database() m.disconnect() __logger__.debug("...Database \"%s\" is deleted" % database_name.lower())
def copy_properties_file_from_and_sudo(step, file_name, sudo_run): """ copy properties.json specific to feature from setting folder, read properties and create necessaries class :param step: :param file_name: file name of configuration associated at features, stored in settings folder :param sudo_run: with superuser privileges (True | False) """ if not world.background_executed: properties = Properties(file=file_name, sudo=sudo_run) properties.read_properties() properties.storing_dictionaries()
def initial_conf(file_name, sudo_run): """ define initial config simulate background in lettuce :param file_name: :param sudo_run: """ print colored(" Background: in terrain...", 'white', 'on_grey', attrs=['bold']) print colored(" Given starting the configuration from terrain...", 'green', 'on_grey', attrs=['bold']) properties = Properties (file=file_name, sudo=sudo_run) print colored(" And updating properties.json from %s" % file_name, 'green', 'on_grey', attrs=['bold']) properties.read_properties() print colored(" And reading properties", 'green', 'on_grey', attrs=['bold']) properties.storing_dictionaries() print colored(" And creating instances to sth and mongo with properties", 'green', 'on_grey', attrs=['bold']) world.sth.sth_service("restart") print colored(" And restarting sth service", 'green', 'on_grey', attrs=['bold']) world.sth.verify_sth_version() print colored(" And verifying sth version", 'green', 'on_grey', attrs=['bold']) world.sth.verify_mongo_version() print colored(" And verifying mongo version", 'green', 'on_grey', attrs=['bold']) if properties.get_drop_all_databases().lower().find("true") >=0: world.sth.drop_all_test_databases() print colored(" And drop all tests databases with prefix: sth_test", 'green', 'on_grey', attrs=['bold']) print colored(" Then completed the configuration from terrain...", 'green', 'on_grey', attrs=['bold'])
import behave from behave import step from iotqatools.helpers_utils import * from iotqatools.cb_v2_utils import CB from iotqatools.mongo_utils import Mongo from tools.properties_config import Properties # methods in properties class from tools.NGSI_v2 import NGSI # constants CONTEXT_BROKER_ENV = u'context_broker_env' MONGO_ENV = u'mongo_env' properties_class = Properties() props_mongo = properties_class.read_properties()[MONGO_ENV] # mongo properties dict behave.use_step_matcher("re") __logger__ = logging.getLogger("steps") # ------------------ create_entities ------------------------------------------------ @step(u'a definition of headers') def service_and_service_path(context): """ configuration of service an service path in headers :param context: It’s a clever place where you and behave can store information to share around. It runs at three levels, automatically managed by behave. """
""" __author__ = 'Iván Arias León (ivan dot ariasleon at telefonica dot com)' from components.common_steps.general_steps import * from iotqatools.fabric_utils import FabricSupport from iotqatools.mongo_utils import Mongo from iotqatools.cb_v2_utils import CB from iotqatools.helpers_utils import * from tools.properties_config import Properties # methods in properties class # constants CONTEXT_BROKER_ENV = u'context_broker_env' MONGO_ENV = u'mongo_env' properties_class = Properties() props_cb = properties_class.read_properties()[CONTEXT_BROKER_ENV] # context broker properties dict props_mongo = properties_class.read_properties()[MONGO_ENV] # mongo properties dict behave.use_step_matcher("re") __logger__ = logging.getLogger("steps") @step(u'update properties test file from "([^"]*)" and sudo local "([^"]*)"') def update_properties_file(context, properties_file, sudo_run): """ update properties.py file from setting folder or jenkins console :param context: It’s a clever place where you and behave can store information to share around. It runs at three levels, automatically managed by behave. :param properties_file: file to get data to update properties.py """ __logger__.debug("Updating properties.json file...")
""" __author__ = 'Iván Arias León (ivan dot ariasleon at telefonica dot com)' import behave from behave import step from iotqatools.helpers_utils import * from iotqatools.mongo_utils import Mongo from tools.NGSI_v2 import NGSI from tools.properties_config import Properties # constants CONTEXT_BROKER_ENV = u'context_broker_env' MONGO_ENV = u'mongo_env' properties_class = Properties() props_mongo = properties_class.read_properties()[ MONGO_ENV] # mongo properties dict behave.use_step_matcher("re") __logger__ = logging.getLogger("steps") # ------------------------- delete steps ---------------------------- @step(u'delete entities with id "([^"]*)"') def delete_entities_by_id(context, entity_id): """ delete entities :param context: It’s a clever place where you and behave can store information to share around. It runs at three levels, automatically managed by behave. :param entity_id: entity id name
import behave from behave import step from iotqatools.helpers_utils import * from iotqatools.cb_v2_utils import CB from iotqatools.mongo_utils import Mongo from tools.properties_config import Properties # methods in properties class from tools.NGSI_v2 import NGSI # constants CONTEXT_BROKER_ENV = u'context_broker_env' MONGO_ENV = u'mongo_env' properties_class = Properties() behave.use_step_matcher("re") __logger__ = logging.getLogger("steps") # ------------------ create_entities ------------------------------------------------ @step(u'a definition of headers') def definition_of_headers(context): """ configuration of different header (service, service path, Content-Type, Accept, etc) :param context: It’s a clever place where you and behave can store information to share around. It runs at three levels, automatically managed by behave. """ __logger__.info("Reading CB properties from properties.json file...") props = properties_class.read_properties()[CONTEXT_BROKER_ENV]
iot_support at tid dot es """ __author__ = 'Iván Arias León (ivan dot ariasleon at telefonica dot com)' from components.common_steps.general_steps import * from iotqatools.fabric_utils import FabricSupport from iotqatools.mongo_utils import Mongo from iotqatools.cb_v2_utils import CB from iotqatools.helpers_utils import * from tools.properties_config import Properties # methods in properties class # constants CONTEXT_BROKER_ENV = u'context_broker_env' MONGO_ENV = u'mongo_env' properties_class = Properties() props_cb = properties_class.read_properties()[ CONTEXT_BROKER_ENV] # context broker properties dict props_mongo = properties_class.read_properties()[ MONGO_ENV] # mongo properties dict behave.use_step_matcher("re") __logger__ = logging.getLogger("steps") @step(u'update properties test file from "([^"]*)" and sudo local "([^"]*)"') def update_properties_file(context, properties_file, sudo_run): """ update properties.py file from setting folder or jenkins console :param context: It’s a clever place where you and behave can store information to share around. It runs at three levels, automatically managed by behave. :param properties_file: file to get data to update properties.py