Best Python code snippet using molecule_python
sdk_metrics.py
Source:sdk_metrics.py
1# Run sdk_metrics.py to start up the prometheus server2import rest_api3from graphQL import GraphQLQuery4import logging5from prometheus_client import start_http_server, Gauge6REPOSITORY_COUNT = Gauge('number_of_repositories', 'name_of_the_operator', ['Kind_of_operator'])7ANSIBLE_VERSION_DATA = Gauge('name_of_repositories', 'version_of_operator', ['name', 'version'])8ANSIBLE_VERSION = Gauge('ansible_version', 'version_of_operator', ['version'])9HELM_VERSION = Gauge('helm_version', 'version_of_operator', ['version'])10GO_VERSION = Gauge('go_version', 'version_of_operator', ['version'])11ANSIBLE_STARS = Gauge('ans_repo_stars', 'stars', ['name_of_repository'])12HELM_STARS = Gauge('helm_repo_stars', 'stars', ['name_of_repository'])13if __name__ == '__main__':14 # Get repository names using rest_api. Pass on the list to15 # GraphQL and get required details16 ansible_repo = rest_api.get_ansible_repositories()17 ansible = GraphQLQuery(ansible_repo)18 ansible_version = ansible.repo_versions("ansible")19 ansible_version_stat = ansible.version_count()20 ansible_repo_stars = ansible.get_stargazers()21 # Uncomment only for debug - (or else will slow down the process!)22 # print(len(ansible_version))23 # print(ansible_repo_stars)24 helm_repo = rest_api.get_helm_repositories()25 # print(helm_repo)26 helm = GraphQLQuery(helm_repo)27 helm_version = helm.repo_versions("helm")28 helm_version_stat = helm.version_count()29 helm_repo_stars = helm.get_stargazers()30 # Uncomment only for debug31 # print(helm_version_stat)32 # print(helm_repo_stars)33 go_repo = rest_api.get_go_repositories()34 go = GraphQLQuery(go_repo)35 # go_version = go.repo_versions("go")36 number_of_go_repositories = go.number_of_go_operators()37 go_version_stat = go.version_count()38 # Uncomment only for debug39 # print("number of go operators")40 # print(number_of_go_repositories)41 # print("go_version_stat")42 # print(go_version_stat)43 ################ PROMETHEUS #######################################44 # Start up the server to expose the metrics.45 start_http_server(8000)46 logging.info("Starting Prometheus server")47 while True:48 REPOSITORY_COUNT.labels("Ansible").set(len(ansible_version))49 REPOSITORY_COUNT.labels("Helm").set(len(helm_version))50 REPOSITORY_COUNT.labels("Go").set(number_of_go_repositories)51 for name, version in ansible_version.items():52 ANSIBLE_VERSION_DATA.labels(name, version).set(1)53 # Iterate to get ansible versions:54 for version, count in ansible_version_stat.items():55 if version is not None:56 details = version.split(":")57 ver = details[1]58 ANSIBLE_VERSION.labels(ver).set(count)59 # Iterate to get helm version:60 for version, count in helm_version_stat.items():61 if version is not None:62 details = version.split(":")63 ver = details[1]64 HELM_VERSION.labels(ver).set(count)65 # Iterate to get go version:66 for version, count in go_version_stat.items():67 if version is not None:68 details = version.split(" ")69 ver = details[1]70 GO_VERSION.labels(ver).set(count)71 # Iterate to log ansible stargazers:72 for name, stars in ansible_repo_stars.items():73 # Do not include operator-sdk itself74 if name != "operator-sdk":75 ANSIBLE_STARS.labels(name).set(stars)76 # Iterate to log helm stargazers:77 for name, stars in helm_repo_stars.items():78 if name != "operator-sdk":...
teem_check.py
Source:teem_check.py
1#!/usr/bin/python2import json3from distutils.version import LooseVersion4from ansible.module_utils.basic import AnsibleModule5def process_json(data, ansible_version, atc_version):6 try:7 assert data["class"]8 assert data["class"].lower() == "as3"9 assert LooseVersion(atc_version["version"]) >= LooseVersion("3.18")10 assert data["declaration"]11 assert data["declaration"]["class"].lower() == "adc"12 if "controls" in data["declaration"]:13 assert not data["declaration"]["controls"]["userAgent"]14 except AssertionError:15 return (False, data)16 as3_declaration = data["declaration"]17 if "controls" not in as3_declaration:18 adc_controls = {19 "class": "Controls",20 "userAgent": "ansible/{ansible_version}".format(21 ansible_version=ansible_version)22 }23 data["declaration"]["controls"] = adc_controls24 else:25 data["declaration"]["controls"]["userAgent"] = \26 "ansible/{ansible_version}".format(27 ansible_version=ansible_version)28 return (True, data)29def main():30 module = AnsibleModule(31 argument_spec=dict(32 atc_json_data=dict(type='json', required=True),33 atc_version=dict(type='json', required=True)34 ),35 supports_check_mode=True,36 )37 atc_json_data = module.params['atc_json_data']38 atc_version = module.params['atc_version']39 atc_json_data = json.loads(atc_json_data)40 atc_version = json.loads(atc_version)41 (isChanged, result) = process_json(atc_json_data,42 module.ansible_version,43 atc_version)44 results = dict(45 changed=isChanged,46 result=result47 )48 module.exit_json(**results)49if __name__ == '__main__':...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!