How to use _load_state method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...35 return True36def _save_state(details):37 with salt.utils.files.fopen(FILENAME, "wb") as pck:38 pickle.dump(details, pck)39def _load_state():40 try:41 if six.PY3 is True:42 mode = "rb"43 else:44 mode = "r"45 with salt.utils.files.fopen(FILENAME, mode) as pck:46 DETAILS = pickle.load(pck)47 except EOFError:48 DETAILS = {}49 DETAILS["initialized"] = False50 _save_state(DETAILS)51 return DETAILS52# Every proxy module needs an 'init', though you can53# just put DETAILS['initialized'] = True here if nothing54# else needs to be done.55def init(opts):56 log.debug("dummy proxy init() called...")57 DETAILS["initialized"] = True58 _save_state(DETAILS)59def initialized():60 """61 Since grains are loaded in many different places and some of those62 places occur before the proxy can be initialized, return whether63 our init() function has been called64 """65 DETAILS = _load_state()66 return DETAILS.get("initialized", False)67def grains():68 """69 Make up some grains70 """71 DETAILS = _load_state()72 if "grains_cache" not in DETAILS:73 DETAILS["grains_cache"] = {74 "dummy_grain_1": "one",75 "dummy_grain_2": "two",76 "dummy_grain_3": "three",77 }78 _save_state(DETAILS)79 return DETAILS["grains_cache"]80def grains_refresh():81 """82 Refresh the grains83 """84 DETAILS = _load_state()85 DETAILS["grains_cache"] = None86 _save_state(DETAILS)87 return grains()88def fns():89 return {90 "details": "This key is here because a function in "91 "grains/ called fns() here in the proxymodule."92 }93def service_start(name):94 """95 Start a "service" on the dummy server96 """97 DETAILS = _load_state()98 DETAILS["services"][name] = "running"99 _save_state(DETAILS)100 return "running"101def service_stop(name):102 """103 Stop a "service" on the dummy server104 """105 DETAILS = _load_state()106 DETAILS["services"][name] = "stopped"107 _save_state(DETAILS)108 return "stopped"109def service_restart(name):110 """111 Restart a "service" on the REST server112 """113 return True114def service_list():115 """116 List "services" on the REST server117 """118 DETAILS = _load_state()119 return list(DETAILS["services"])120def service_status(name):121 """122 Check if a service is running on the REST server123 """124 DETAILS = _load_state()125 if DETAILS["services"][name] == "running":126 return {"comment": "running"}127 else:128 return {"comment": "stopped"}129def package_list():130 """131 List "packages" installed on the REST server132 """133 DETAILS = _load_state()134 return DETAILS["packages"]135def package_install(name, **kwargs):136 """137 Install a "package" on the REST server138 """139 DETAILS = _load_state()140 if kwargs.get("version", False):141 version = kwargs["version"]142 else:143 version = "1.0"144 DETAILS["packages"][name] = version145 _save_state(DETAILS)146 return {name: version}147def upgrade():148 """149 "Upgrade" packages150 """151 DETAILS = _load_state()152 pkgs = uptodate()153 DETAILS["packages"] = pkgs154 _save_state(DETAILS)155 return pkgs156def uptodate():157 """158 Call the REST endpoint to see if the packages on the "server" are up to date.159 """160 DETAILS = _load_state()161 for p in DETAILS["packages"]:162 version_float = float(DETAILS["packages"][p])163 version_float = version_float + 1.0164 DETAILS["packages"][p] = six.text_type(version_float)165 return DETAILS["packages"]166def package_remove(name):167 """168 Remove a "package" on the REST server169 """170 DETAILS = _load_state()171 DETAILS["packages"].pop(name)172 _save_state(DETAILS)173 return DETAILS["packages"]174def package_status(name):175 """176 Check the installation status of a package on the REST server177 """178 DETAILS = _load_state()179 if name in DETAILS["packages"]:180 return {name: DETAILS["packages"][name]}181def ping():182 """183 Degenerate ping184 """185 log.debug("dummy proxy returning ping")186 return True187def shutdown(opts):188 """189 For this proxy shutdown is a no-op190 """191 log.debug("dummy proxy shutdown() called...")192 DETAILS = _load_state()193 if "filename" in DETAILS:194 os.unlink(DETAILS["filename"])195def test_from_state():196 """197 Test function so we have something to call from a state198 :return:199 """200 log.debug("test_from_state called")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?