It is interesting how things transpired with these functional tests I wrote. First it was just a number of "this is passed" and "that is failed", but I needed to see more, so when something failed I could have a chance to do fixes. After a while I added more and more information, I started to share the output with others and tried to add paragraphs so they also have a chance to understand things. The tests grew bigger and bigger, I added titles to organize the parts and when I needed subtitles I started to think of them as documents, not simply the output of some BASH script.
All these of course were just ASCII text in a terminal, colorful, some UTF-8, but still, text. Then I wrote a huge sed line that simply transformed the ANSI color sequences to HTML code and before long I had some actual documents viewed in a web browser as a user documentation.
I know, nothing was invented here, these things are pretty standard I guess, others must do it too, but the thing is that these are still just some BASH scripts, no special software package is used, no professional test environment, everything is just a set of scripts. They grown and gained a foothold. I don't feel I developed something, these are just test scripts that happened because I needed tests. Strange isn't it?
So I can do this! I copypasted some test cases for you guys here. The rest of this article is actually coming from BASH, how cool is that?
This is where we create the initial Cmon user. It is the initial because there is no user defined in the s9s configuration file and in the command line either. When this happens the s9s will access the controller through SSH and push the user creation command through a named pipe the Cmon Controller provided for exactly this reason. So there is a passwordless ssh and a passwordless sudo is behind this. If these are not possible you need to ssh to the controller host and do this as root. After the initial user created we also register a public key so that the Cmon user account can be used without password.
pipas@core2:tests$ s9s user \ --create \ --group="testgroup" \ --create-group \ --generate-key \ --controller="https://localhost:9556" \ --new-password="p" \ --email-address="email@example.com" \ --first-name="pipas" \ --last-name="pipas" \ --batch \ pipas o Return code is 0, ok. pipas@core2:tests$ s9s user \ --add-key \ --password="p" \ --public-key-file="/home/pipas/.ssh/id_rsa.pub" \ --public-key-name="The_SSH_key" Ok.
The creation of the initial user changes the configuration file. The s9s program automatically puts the username into the configuration file so that next time it can be used without passing the account name in the command line.
# # This configuration file was created by ft_proxysql_os.sh version 0.0.1. # [global] controller = https://localhost:9556 cmon_user=pipas [network] client_connection_timeout = 30 [log] #brief_job_log_format = "%36B:%-5L: %-7S %M\n" #brief_log_format = "%C %36B:%-5L: %-8S %M\n" brief_job_log_format = "%-8S %M\n" brief_log_format = "%-8S %M\n" log_file = "/home/pipas/s9s.log"
Here we register an LXC server that will be used to create containers. No software will be installed, just the registration is done here, the server should be fully prepared to run LXC containers already.
pipas@core2:tests$ s9s server --register --servers=lxc://core2 Registered. o The exit code is 0, ok. pipas@core2:tests$ s9s server --stat core2 core2 (127.0.1.1) Name: core2 CDT path: / Class: CmonLxcServer Owner: pipas/testgroup ID: 1 ACL: rwxrwx--- IP: 127.0.1.1 Protocol: lxc Status: CmonHostOnline OS: - Alias: - Model: Sun Fire X4600 M2 (501-7638-06) Summary: 4 VMs, 128GB RAM, 8 CPUs, 32 cores, 32 threads Limits: -/- VMs CPU(s): 8 x Quad-Core AMD Opteron(tm) Processor 8384 NIC(s): 4 x 82546EB Gigabit Ethernet Controller (Copper) Banks: 32 x 4 Gbyte DIMM DDR2 Synchronous 333 MHz (3.0 ns) Disks: 1 x HP DG146ABAB4 1 x HP DG146BABCF 2 x HP DG146BB976 S CLOUD OWNER GROUP IP ADDRESS NAME s lxc pipas testgroup - pipevo u lxc pipas testgroup 192.168.0.182 python s lxc pipas testgroup - ubuntu s lxc pipas testgroup - ubuntu-s9s o The exit code is 0, ok. o The container server has class CmonLxcServer, ok. pipas@core2:tests$ s9s tree --cat /core2/.runtime/state container_server_instance : 0x7f462c0358d0 UUID : d87aa9ae-b090-44f5-94c4-91c1cd71b84b container_server_class : CmonLxcServer server_name : core2 number_of_containers : 4 last_command : None model : Sun Fire X4600 M2 (501-7638-06) cpu_model : Quad-Core AMD Opteron(tm) Processor 8384 number_of_processors : 8 number_of_cpu_threads : 32 total_memory : 135268401152 total_memory_gbyte : 126
This test actually implements a subtask. It is creating a container on the registered container server. Since the test might ned multiple containers this might be executed several times.
pipas@core2:tests$ s9s container \ --create \ --image="centos_6" \ --servers="core2" \ --log \ ft_proxysql_os_01_022582 MESSAGE Preparing to create containers. MESSAGE File '/usr/sbin/cmon-cloud' does not exist, no local cmon-cloud. MESSAGE No existing cluster is related to the containers. MESSAGE Creating 1 containers. MESSAGE Checking the job owner. MESSAGE Owner of the job is pipas. MESSAGE Creating container 0. MESSAGE Checking servers. MESSAGE Selected server 'core2' to hold the container. MESSAGE Container name is ft_proxysql_os_01_022582. MESSAGE Creating container holding centos 6. MESSAGE Created container ft_proxysql_os_01_022582 on server core2. MESSAGE Writing file 'core2:/var/lib/lxc/ft_proxysql_os_01_022582/config'. MESSAGE Starting container. MESSAGE Installing openssh-server on the container. MESSAGE Creating account pipas on the container. MESSAGE Registering 2 public key(s) for account pipas. MESSAGE Enabling passwordless sudo for user pipas. MESSAGE Checking container 'ft_proxysql_os_01_022582'. MESSAGE Waiting the container to get an IP address (2019-10-29 13:24:26). MESSAGE Checking container 'ft_proxysql_os_01_022582'. MESSAGE The container obtained '192.168.0.228' IPv4 address. MESSAGE Container is created as follows: MESSAGE Name is 'ft_proxysql_os_01_022582'. MESSAGE Server is 'core2'. MESSAGE Provider is 'lxc'. MESSAGE Region is 'region1'. MESSAGE Image is 'centos_6'. MESSAGE Template is ''. MESSAGE Subnet is 'core2-br0'. MESSAGE VPC is 'vpc-region1'. MESSAGE Firewall is '-'. o The exit code is 0, ok pipas@core2:tests$ s9s container --stat ft_proxysql_os_01_022582 ft_proxysql_os_01_022582 (192.168.0.228) Name: ft_proxysql_os_01_022582 CDT path: /core2/containers Class: CmonContainer Owner: pipas/testgroup ID: 192340da-0400-4127-a600-af8a2cf03f16 ACL: rwxrwx--- IPv4: 192.168.0.228 Type: lxc PublicIp: - PrivateIp: 192.168.0.228 Server: core2 State: RUNNING Cloud: lxc Region: region1 Subnet: core2-br0 CIDR: 192.168.0.18/16 VPC ID: vpc-region1 Firewall: - Template: - Image: centos_6 OS: centos 6.10 final Arch: x86_64 Start: n Limits: Config: '/var/lib/lxc/ft_proxysql_os_01_022582/config' Root FS: '/var/lib/lxc/ft_proxysql_os_01_022582/rootfs' o Container ft_proxysql_os_01_022582 has IP 192.168.0.228, ok o The owner of the container is 'pipas', ok o SSH access granted for user 'pipas' on 192.168.0.228, ok. o The group of the container is testgroup, ok o The path of the container is /core2/containers, ok o The acl of the container is 'rwxrwx--- ', ok o The cloud of the container is lxc, ok o The state of the container is RUNNING, ok o The parent of the container is core2, ok o The prot of the container is lxc, ok o Container with IP 192.168.0.228 created, ok.