In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what are the methods of Linux testing resource agent". In the daily operation, I believe that many people have doubts about the method of Linux testing resource agent. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what are the methods of Linux testing resource agent?" Next, please follow the editor to study!
10 Test Resource Agent
This chapter discusses automated testing of resource agents. Testing is a very critical issue in development, and it is very important to develop new resource agents and modify existing resource agents.
10.1 testing with ocf_tester
The resource agent repository (including all resource agent packages) has an application called ocf_tester. This script can be easily used to test your resource agent.
Ocf_tester is usually called as the root user, like this:
one
Ocf-tester-n [- o =...]
Is an arbitrary resource name
You can set any parameter you want with the-o option.
Is the full path of your resource agent
When called, the ocf-tester performs all mandatory operations (see Chapter 5 Resource Agent behavior)
You can also test optional actions. The optional action must conform to its declared behavior, and if it is not implemented, ocf-tester will mark an error flag.
Important:
Ocf-tester does not support the "dry run" of operations, nor does it produce any resource replicas. It runs the same as the actual resource agent, regardless of whether it opens and closes the database, mounts the file system, starts or stops the virtual machine, and so on. So, be careful.
For example, you can run to use ocf-tester on the foobar resource agent, as follows:
one
two
three
four
five
six
seven
eight
# ocf-tester-n foobartest\
-o superfrobnicate=true\
-o datadir=/tmp\
/ home/johndoe/ra-dev/foobar
Beginning tests for / home/johndoe/ra-dev/foobar...
* Your agent does not support the notify action (optional)
* Your agent does not support the reload action (optional)
/ home/johndoe/ra-dev/foobar passed all tests
10.2 testing with ocft
Ocft is also a resource agent testing tool. Unlike ocf-tester, ocft can automatically generate complex test environments, including package installation and arbitrary shell scripts.
10.2.1 ocft components
Ocft contains the following components:
A test case generator (/ usr/sbin/ocf)-generate shell scripts from the test case configuration file
Configuration file (/ usr/share/resource-agents/ocft/configs)-A configuration file that contains environment variable settings and a resource agent profile
Test scripts are saved in / var/lib/resource-agents/ocft/cases/, but usually don't need to worry about them
10.2.2 Custom Test Environment
Ocft modifies the runtime environment of the resource agent, either by changing the environment variable (using the interface defined by OCF) or by running an ad-hoc shell script that can change permissions or unmount a file system.
10.2.3 how to test
You must understand the software you want to test, draw a sketch of all interested run scenarios, and mark all expected and unexpected conditions and the results that the resource agent should run. Then, you need to code these conditions and expected run results into ocft test columns. This makes it easy to run ocft:
one
two
# ocft make
# ocft test
The first command generates a test case script, and the second command runs the resulting script and checks the output.
10.2.4 ocf profile syntax
There are four first-level selections, and there are one or more sub-options under each level-1 option
CONFIG (first-tier option)
This option is global and affects every test case
AgentRoot (suboption)
one
AgentRoot / usr/lib/ocf/resource.d/xxx
Normally, we assume that the resource proxy script exists in the directory of the heartbeat provider. Use AgentRoot to test whether the agent is distributed in a different directory.
InstallPackage (suboption)
one
InstallPackage package [package2 [...]]
Test the package you need, and if the package is already installed, it will no longer be installed.
HangTimeout (suboption)
one
HangTimeout secs
The maximum execution time for running a resource agent operation, after which the operation is deemed to be invalid.
SETUP-AGENT (first-tier option)
one
two
SETUP-AGENT
Bash commands
If the resource agent needs to be initialized before testing, you can place the bash code here. Initialization is completed only once. If you need to initialize again, you can delete the / tmp/. [agent _ NAME] _ set tag file.
CASE (first-tier option)
one
CASE "description"
This is the main building block of the test suite. Each test column can be described in a CASE option. A use case consists of if suboptions followed by the RunAgent suboption.
Var (suboption)
one
Var VARIABLE=value
This is to set the environment variable for the resource agent. Usually displayed as OCF_RESKEY_xxx, note that there are no spaces around the assignment symbol "=".
Unvar (suboption)
one
Unvar VARIABLE [VARIABLE2 [...]]
Remove an environment variable
Include (suboption)
one
Include macro_name
Contains the macro macro_name. Refer to CASE-BLOCK below.
Bash (suboption)
one
Bash bash_codes
This option sets the operating system environment variable, and you can insert BASH code to customize the system environment. Be careful not to cause unrecoverable results.
BashAtExit (suboption)
one
BashAtExit bash_codes
This option restores the operating system environment so that the new test case runs correctly. Of course, you can also use the Bash option directly to restore. However, if an error occurs in the process, the script says to exit without running the recovered code, in which case you should use BashAtExit, and you can restore the system environment before exiting.
RunAgent (suboption)
one
RunAgent cmd [ret_value]
This option runs the resource agent. "cmd" is the parameter of the resource agent, such as "start,status,stop...". The second parameter is optional. Can be used to compare the return and expected values of the results of running the script. If not, you should be able to find some bug.
It can also be executed remotely rather than locally. The protocol used is ssh, and the program runs in the background. You just need to add @ after the suboption. As follows:
one
Bash@192.168.1.100 date
The above example runs the date program. Remote commands are run in the background.
NB: these still need to be explained.
CASE-BLOCK (first-tier option)
The CASE-BLOCK option defines macros that can be included in the CASE. All suboptions of CASE are available.
At this point, the study on "what are the methods of Linux testing resource agent" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.