How to use configured method in avocado

Best Python code snippet using avocado_python

test_cluster.py

Source:test_cluster.py Github

copy

Full Screen

1import functools2import requests3from yaml import CLoader as Loader4import utils5testinfra_hosts = utils.get_testinfra_hosts()6def get_configured_replicasets():7 inventory = utils.get_inventory()8 replicasets = {}9 for instance in inventory.get_hosts():10 instance_vars = utils.get_instance_vars(instance)11 if 'replicaset_alias' not in instance_vars:12 continue13 if utils.instance_is_expelled(instance_vars) or utils.instance_is_stateboard(instance_vars):14 continue15 replicaset_alias = instance_vars['replicaset_alias']16 if replicaset_alias not in replicasets:17 replicasets[replicaset_alias] = {18 'instances': [],19 'failover_priority': instance_vars.get('failover_priority'),20 'roles': instance_vars['roles'],21 'all_rw': instance_vars.get('all_rw'),22 'weight': instance_vars.get('weight'),23 'vshard_group': instance_vars.get('vshard_group')24 }25 replicasets[replicaset_alias]['instances'].append(instance.get_name())26 return replicasets27def get_deps_by_roles(admin_api_url):28 query = '''29 query {30 cluster {31 known_roles {32 name33 dependencies34 }35 }36 }37 '''38 session = utils.get_authorized_session()39 response = session.post(admin_api_url, json={'query': query})40 data = utils.get_response_data(response)41 known_roles = data['cluster']['known_roles']42 return {r['name']: r['dependencies'] for r in known_roles}43def user_is_deleted(user):44 return 'deleted' in user and user['deleted'] is True45def section_is_deleted(section):46 return 'deleted' in section and section['deleted'] is True47def aliases_in_priority_order(replicaset_servers):48 return [s['alias'] for s in sorted(replicaset_servers, key=lambda x: x['priority'])]49def test_replicasets():50 # Get all configured instances51 configured_instances = utils.get_configured_instances()52 if not configured_instances:53 return54 # Select one instance to be control55 admin_api_url = utils.get_admin_api_url()56 # Get started replicasets57 query = '''58 query {59 replicasets {60 alias61 roles62 all_rw63 weight64 vshard_group65 servers {66 alias67 priority68 }69 master {70 alias71 }72 }73 }74 '''75 session = utils.get_authorized_session()76 response = session.post(admin_api_url, json={'query': query})77 data = utils.get_response_data(response)78 started_replicasets = data['replicasets']79 started_replicasets = {r['alias']: r for r in started_replicasets}80 configured_replicasets = get_configured_replicasets()81 deps_by_roles = get_deps_by_roles(admin_api_url)82 # Check if started replicasets are equal to configured83 assert len(started_replicasets) == len(configured_replicasets)84 assert set(started_replicasets.keys()) == set(configured_replicasets.keys())85 for name in started_replicasets.keys():86 started_replicaset = started_replicasets[name]87 configured_replicaset = configured_replicasets[name]88 exp_roles = list(functools.reduce(89 lambda roles, role: roles + deps_by_roles[role],90 started_replicaset['roles'],91 started_replicaset['roles'],92 ))93 assert set(started_replicaset['roles']) == set(exp_roles)94 started_replicaset_instances = [i['alias'] for i in started_replicaset['servers']]95 assert set(started_replicaset_instances) == set(configured_replicaset['instances'])96 if configured_replicaset['failover_priority'] is not None:97 configured_failover_priority = configured_replicaset['failover_priority']98 assert started_replicaset['master']['alias'] == configured_failover_priority[0]99 failover_priority = aliases_in_priority_order(started_replicaset['servers'])100 assert failover_priority[:len(configured_failover_priority)] == configured_failover_priority101 if configured_replicaset['all_rw'] is not None:102 assert started_replicaset['all_rw'] == configured_replicaset['all_rw']103 if configured_replicaset['weight'] is not None:104 assert started_replicaset['weight'] == configured_replicaset['weight']105 if configured_replicaset['vshard_group'] is not None:106 assert started_replicaset['vshard_group'] == configured_replicaset['vshard_group']107def test_failover():108 # Get configured failover status109 configured_failover_params = utils.get_cluster_var('cartridge_failover_params')110 if not configured_failover_params:111 return112 # Get all configured instances113 configured_instances = utils.get_configured_instances()114 if not configured_instances:115 return116 # Select one instance to be control117 admin_api_url = utils.get_admin_api_url()118 # Get cluster failover status119 query = '''120 query {121 cluster {122 failover_params {123 mode124 state_provider125 tarantool_params {126 uri127 password128 }129 failover_timeout130 fencing_enabled131 fencing_timeout132 fencing_pause133 }134 }135 }136 '''137 session = utils.get_authorized_session()138 response = session.post(admin_api_url, json={'query': query})139 data = utils.get_response_data(response)140 failover_params = data['cluster']['failover_params']141 failover_params_names = [142 'failover_timeout',143 'fencing_enabled',144 'fencing_timeout',145 'fencing_pause',146 ]147 for param_name in failover_params_names:148 if param_name in configured_failover_params:149 assert failover_params[param_name] == configured_failover_params[param_name]150 assert failover_params['mode'] == configured_failover_params['mode']151 if configured_failover_params.get('state_provider') is not None:152 if configured_failover_params['state_provider'] == 'stateboard':153 assert failover_params['state_provider'] == 'tarantool'154 if configured_failover_params.get('stateboard_params') is not None:155 assert 'tarantool_params' in failover_params156 configured_stateboard_params = configured_failover_params['stateboard_params']157 stateboard_params = failover_params['tarantool_params']158 for p in ['uri', 'password']:159 if configured_stateboard_params.get(p) is not None:160 assert stateboard_params[p] == configured_stateboard_params[p]161def test_auth_params():162 # Get configured auth params163 configured_auth = utils.get_cluster_var('cartridge_auth')164 if not configured_auth:165 return166 # Get all configured instances167 configured_instances = utils.get_configured_instances()168 if not configured_instances:169 return170 # Select one instance to be control171 admin_api_url = utils.get_admin_api_url()172 # Get cluster auth params173 query = '''174 query {175 cluster {176 auth_params {177 enabled178 cookie_max_age179 cookie_renew_age180 }181 }182 }183 '''184 session = utils.get_authorized_session()185 response = session.post(admin_api_url, json={'query': query})186 data = utils.get_response_data(response)187 auth = data['cluster']['auth_params']188 for key in ['enabled', 'cookie_max_age', 'cookie_renew_age']:189 if key in configured_auth:190 assert auth[key] == configured_auth[key]191def test_auth_users():192 # Get configured auth params193 configured_auth = utils.get_cluster_var('cartridge_auth')194 if not configured_auth or 'users' not in configured_auth:195 return196 # Get all configured instances197 configured_instances = utils.get_configured_instances()198 if not configured_instances:199 return200 # Select one instance to be control201 admin_api_url = utils.get_admin_api_url()202 # Get cluster auth params203 query = '''204 query {205 cluster {206 users {207 username208 fullname209 email210 }211 }212 }213 '''214 session = utils.get_authorized_session()215 response = session.post(admin_api_url, json={'query': query})216 data = utils.get_response_data(response)217 auth_users = data['cluster']['users']218 auth_users = {219 u['username']: u for u in auth_users220 if u['username'] != 'admin' and not user_is_deleted(u)221 }222 configured_users = {u['username']: u for u in configured_auth['users']}223 assert auth_users.keys() == configured_users.keys()224 for k in auth_users.keys():225 conf_user = configured_users[k]226 user = auth_users[k]227 for p in ['fullname', 'email']:228 if p in conf_user:229 assert user[p] == conf_user[p]230 # Check if all users can log in231 login_url = '%s/login' % utils.get_any_instance_url()232 for username, user in configured_users.items():233 if 'password' not in user:234 continue235 response = requests.post(login_url, json={'username': username, 'password': user['password']})236 assert response.status_code == 200237def test_app_config():238 # Get configured auth params239 specified_app_config = utils.get_cluster_var('cartridge_app_config')240 if not specified_app_config:241 return242 # Get all configured instances243 configured_instances = utils.get_configured_instances()244 if not configured_instances:245 return246 # Get cartridge app config247 config_url = '%s/admin/config' % utils.get_any_instance_url()248 session = utils.get_authorized_session()249 response = session.get(config_url)250 assert response.status_code == 200251 loader = Loader(response.content)252 app_config = loader.get_data()253 # Check if app config is equal to configured one254 for section_name, section in specified_app_config.items():255 if section_is_deleted(section):256 assert section_name not in app_config257 else:258 assert section_name in app_config259 assert app_config[section_name] == section['body']260def test_cluster_has_no_issues():261 # Get all configured instances262 configured_instances = utils.get_configured_instances()263 if not configured_instances:264 return265 # Select one instance to be control266 admin_api_url = utils.get_admin_api_url()267 # Get cluster auth params268 query = '''269 query {270 cluster {271 issues {272 topic273 message274 }275 }276 }277 '''278 session = utils.get_authorized_session()279 response = session.post(admin_api_url, json={'query': query})280 data = utils.get_response_data(response)281 issues = data['cluster']['issues']282 assert len(issues) == 0, 'Found issues: %s' % ', '.join([283 '%s: %s' % (issue['topic'], issue['message'])284 for issue in issues...

Full Screen

Full Screen

BUILD

Source:BUILD Github

copy

Full Screen

...31 deps = ["//tensorflow/stream_executor/platform"],32)33cc_library(34 name = "gpu_activation",35 srcs = if_gpu_is_configured(["gpu_activation.cc"]),36 hdrs = if_gpu_is_configured(["gpu_activation.h"]),37 deps = if_gpu_is_configured([38 ":gpu_activation_header",39 ":gpu_driver_header",40 "//tensorflow/stream_executor",41 "//tensorflow/stream_executor:stream_executor_internal",42 "//tensorflow/stream_executor/platform",43 ]),44)45cc_library(46 name = "gpu_diagnostics_header",47 hdrs = if_gpu_is_configured(["gpu_diagnostics.h"]),48 deps = [49 "//tensorflow/stream_executor/lib",50 "//tensorflow/stream_executor/platform",51 ],52)53cc_library(54 name = "gpu_driver_header",55 hdrs = ["gpu_driver.h"],56 deps = [57 ":gpu_types_header",58 "//tensorflow/stream_executor:device_options",59 "//tensorflow/stream_executor/lib",60 "//tensorflow/stream_executor/platform",61 "@local_config_cuda//cuda:cuda_headers",62 ],63)64cc_library(65 name = "gpu_event_header",66 hdrs = if_gpu_is_configured(["gpu_event.h"]),67 deps = [68 ":gpu_driver_header",69 ":gpu_stream_header",70 "//tensorflow/stream_executor:event",71 "//tensorflow/stream_executor/lib",72 ],73)74cc_library(75 name = "gpu_event",76 srcs = if_gpu_is_configured(["gpu_event.cc"]),77 hdrs = if_gpu_is_configured(["gpu_event.h"]),78 deps = [79 ":gpu_driver_header",80 ":gpu_executor_header",81 ":gpu_stream",82 "//tensorflow/stream_executor:stream_executor_headers",83 "//tensorflow/stream_executor/lib",84 ],85)86cc_library(87 name = "gpu_executor_header",88 hdrs = if_gpu_is_configured(["gpu_executor.h"]),89 deps = [90 ":gpu_kernel_header",91 "//tensorflow/core:lib",92 "//tensorflow/stream_executor:event",93 "//tensorflow/stream_executor:platform",94 "//tensorflow/stream_executor:stream_executor_internal",95 "//tensorflow/stream_executor/lib",96 "//tensorflow/stream_executor/platform",97 "@com_google_absl//absl/strings",98 "@com_google_absl//absl/synchronization",99 ],100)101cc_library(102 name = "gpu_helpers_header",103 hdrs = if_gpu_is_configured(["gpu_helpers.h"]),104 deps = [":gpu_types_header"],105)106cc_library(107 name = "gpu_kernel_header",108 hdrs = if_gpu_is_configured(["gpu_kernel.h"]),109 deps = [110 ":gpu_driver_header",111 "//tensorflow/stream_executor:event",112 "//tensorflow/stream_executor:stream_executor_pimpl_header",113 "//tensorflow/stream_executor/platform",114 ],115)116cc_library(117 name = "gpu_rng_header",118 hdrs = if_gpu_is_configured(["gpu_rng.h"]),119 deps = [120 ":gpu_types_header",121 "//tensorflow/core:lib",122 "//tensorflow/stream_executor:plugin_registry",123 "//tensorflow/stream_executor:rng",124 "//tensorflow/stream_executor/platform",125 "@com_google_absl//absl/synchronization",126 ],127)128cc_library(129 name = "gpu_stream_header",130 hdrs = if_gpu_is_configured(["gpu_stream.h"]),131 deps = [132 ":gpu_driver_header",133 "//tensorflow/core:lib",134 "//tensorflow/stream_executor:stream_executor_internal",135 ],136)137cc_library(138 name = "gpu_stream",139 srcs = if_gpu_is_configured(["gpu_stream.cc"]),140 hdrs = if_gpu_is_configured(["gpu_stream.h"]),141 deps = [142 ":gpu_driver_header",143 ":gpu_executor_header",144 "//tensorflow/core:lib",145 "//tensorflow/stream_executor:stream_executor_headers",146 "//tensorflow/stream_executor:stream_header",147 "//tensorflow/stream_executor/lib",148 "//tensorflow/stream_executor/platform",149 ],150)151cc_library(152 name = "gpu_timer_header",153 hdrs = if_gpu_is_configured(["gpu_timer.h"]),154 deps = [155 ":gpu_driver_header",156 ":gpu_executor_header",157 "//tensorflow/stream_executor:stream_executor_internal",158 ],159)160cc_library(161 name = "gpu_timer",162 srcs = if_gpu_is_configured(["gpu_timer.cc"]),163 hdrs = if_gpu_is_configured(["gpu_timer.h"]),164 deps = [165 ":gpu_driver_header",166 ":gpu_executor_header",167 ":gpu_stream",168 "//tensorflow/stream_executor:stream_executor_headers",169 "//tensorflow/stream_executor/lib",170 ],171)172cc_library(173 name = "gpu_types_header",174 hdrs = if_gpu_is_configured(["gpu_types.h"]),175 deps = [176 "//tensorflow/stream_executor/platform",177 ] + if_cuda_is_configured([178 "@local_config_cuda//cuda:cuda_headers",179 ]) + if_rocm_is_configured([180 "@local_config_rocm//rocm:rocm_headers",181 ]),182)183cc_library(184 name = "gpu_asm_opts",185 hdrs = ["gpu_asm_opts.h"],186 visibility = [187 "//tensorflow/compiler/xla/service/gpu:__subpackages__",188 "//tensorflow/core/kernels:__subpackages__",189 "//tensorflow/stream_executor:__subpackages__",190 ],191 deps = [192 "@com_google_absl//absl/strings",193 "@com_google_absl//absl/types:span",194 ],195)196cc_library(197 name = "asm_compiler",198 srcs = if_gpu_is_configured(["asm_compiler.cc"]),199 hdrs = if_gpu_is_configured(["asm_compiler.h"]),200 copts = tf_copts(),201 visibility = [202 "//tensorflow/compiler/xla/service/gpu:__subpackages__",203 "//tensorflow/compiler/xla/service/mlir_gpu:__subpackages__",204 "//tensorflow/core/kernels:__subpackages__",205 "//tensorflow/stream_executor:__subpackages__",206 "//third_party/tf_runtime/tools/tf_kernel_gen:__subpackages__",207 ],208 deps = if_gpu_is_configured([209 ":gpu_asm_opts",210 ":gpu_driver_header",211 ":gpu_helpers_header",212 "//tensorflow/core:lib",213 "//tensorflow/core:regexp_internal",214 "//tensorflow/core:cuda_libdevice_path",215 "//tensorflow/stream_executor/lib",216 "//tensorflow/stream_executor/platform",217 "@com_google_absl//absl/strings:str_format",218 "@com_google_absl//absl/synchronization",219 "@com_google_absl//absl/types:span",220 "@com_google_absl//absl/container:flat_hash_map",221 ]) + if_cuda_is_configured([222 "//tensorflow/stream_executor/cuda:cuda_driver",223 "//tensorflow/stream_executor/cuda:ptxas_wrapper",224 ]),225)226cc_library(227 name = "redzone_allocator",228 srcs = if_gpu_is_configured(["redzone_allocator.cc"]),229 hdrs = if_gpu_is_configured(["redzone_allocator.h"]),230 copts = tf_copts(),231 visibility = [232 "//tensorflow/compiler/xla/service/gpu:__subpackages__",233 "//tensorflow/core/kernels:__subpackages__",234 "//tensorflow/stream_executor:__subpackages__",235 ],236 deps = if_gpu_is_configured([237 ":asm_compiler",238 ":gpu_asm_opts",239 "@com_google_absl//absl/base",240 "@com_google_absl//absl/container:fixed_array",241 "@com_google_absl//absl/strings:str_format",242 "@com_google_absl//absl/types:optional",243 "//tensorflow/core:allocator",244 "//tensorflow/core:lib",245 "//tensorflow/core:stream_executor_no_cuda",246 "//tensorflow/stream_executor:device_memory",247 "//tensorflow/stream_executor:device_memory_allocator",248 "//tensorflow/stream_executor:stream_executor_headers",249 ]),250)

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:

YouTube

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

Run avocado 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?

Helpful

NotHelpful