Adapter is an ADS component, which is responsible for creating and managing VMs on a particular platform.
The CentOSVZAdapter
is an adapter for the CentOS OpenVZ platform. In
this document, the term VM
and container
are used interchangeably.
CentOSVZAdapter
will create a container on CentOS OpenVZ platform based on the specification given in the lab spec of a particular lab.CentOSVZAdapter
will copy theADS code
to the newly created container and start theVMManager
service.
CentOSVZAdapter
is required to create, start, stop and restart the
container but in the current release, it creates container and
intializes the VMManager
service.
CentOSVZAdapter
works by issuing multiple commands to create
,
set
and start
a VM. It utilizes the vzctl
API to execute
commands. CentOSVZAdapter
contacts base machine through
SSH
to executes commands.
In the current design of ADS
, a fixed set of interfaces to an adapter
is already defined. An adapter is required to implement these
interfaces. This enables other components/services of ADS
to
communicate with the adapter. The interfaces implemented by the
CentOSVZAdapter
are listed below:
- create_vm (self, lab_spec, vm_id=”“)
Creates a new VM.
Parameters:
- lab_spec - Lists the lab and VM related reqirements.
- vm_id - If no vm_id is specified, it is computed using the last two segments of an available IP address.
Returns: VM id of the newly created VM.
- start_vm (self, vm_id)
Starts the VM identified by
vm_id
.Parameters:
- vm_id - vm_id of the VM to be started.
Returns: List of VMs that got started.
- start_vm_manager (self, vm_id )
Starts the VM manager service inside the VM identified by
vm_id
.Parameters:
- vm_id - VM id of the VM to be started.
Returns: True if the VM Manager service has successfully started.
To set the proxies, edit the file ovpl/config/config.json
and
ovpl/src/VMManager/config.json
.
"ENVIRONMENT": { "HTTP_PROXY":"http://proxy.vlabs.ac.in:8080", "HTTPS_PROXY":"http://proxy.vlabs.ac.in:8080" },
if no proxies are used,
"ENVIRONMENT": { "HTTP_PROXY":"", "HTTPS_PROXY":"" },
Also set the SERVER_IP in LOGSERVER_CONFIGURATION to the IP address of the machine on which the ADS services are running.
Edit the file ovpl/src/adapters/settings.py
If the services are running on the base machine, set ADS_ON_CONTAINER to False. If the services are running on a container, set ADS_ON_CONTAINER to True. Set BASE_IP_ADDRESS = "root@<IP>" where IP is the ip address of base machine on which containers are created. Set ADS_SERVER_VM_ID to CTID of container running ADS. ADS_SERVER_VM_ID = "<CTID>" SUBNET field to match with the subnet of your base machine If the ip address of your base machine is 10.2.58.XXX, SUBNET = ["10.2.58.12/28"]
SSH access using key based authentication is allowed on base
machine. So to run the test cases, copy public key from
~/.ssh/id_rsa.pub
of local machine and paste the public key in
authorized_keys ~./ssh/authorized_keys
of Base Machine.
The following sequence diagram depicts the work flow for creation and
intilization of the VM. It takes the lab spec through http
request and creates the VM. CentOSVZAdapter
returns vm_id
, vm_ip
and
vm_manager_port
as a http response to the VMPoolmanager
.
Following is the sequence of events that occur when a lab is deployed
on CentOS platform using CentOSVZAdapter
:
VMPoolManager
sends an HTTP Request toAdapterServer
indicating that a VM needs to be created. It also passes the lab spec that includes VM requirements.- On receiving this request, the
AdapterServer
calls thecreate_vm()
function ofCentOSVZAdapter
and hands over the lab spec to it. - Based on lab spec, the
CentOSVZAdapter
selects OS template. - It creates a VM on Base Machine.
- The
vm_id
of the newly created VM is returned to theAdapterServer
. - The
AdapterServer
now calls theinit_vm()
function ofCentOSVZAdapter
. - This initializes the newly created VM on
CentOSVZAdapter
by copying relevantADS
component (VM Manager) and lab sources, and starting the VM Manager. - Once this service has started, the
CentOSVZAdapter
sends backvm_id
of the VM,vm_ip
of the VM and port on which the VM Manager service is running toAdapterServer
. - Later three parameters (vm_id, vm_ip, vm_manager_port) are
forwarded by
AdapterServer
as HTTP response to theVMPoolManager
.
The implementation of the CentOSVZAdapter
can be found here.
- To validate the creation of a VM.
- To validate the intilization of a VM.
- To ensure that the
VMManagerService
is running on this VM.
This is achieved through unit testing.
- A VM is provisioned on Base Machine, such that it is able to access the internet.
- Edit the
config.json
andsetting.py
as mention above in configuration ADS
is configured and running in the provisioned VM.- Share the
public key
as metioned above in configuration
All unit tests should follow the same basic structure as follows:
- Set up all conditions for testing.
- Call the method (or Trigger) being tested.
- Verify that the results are correct.
- Clean up modified records.
The objective of this test case is to test the creation of a VM on
Base Machine. test_create_vm()
is responsible for testing the
creation of VM and returns vm_id
.
The objective of this test is to validate the intialization of a VM on
Base Machine. test_init_vm()
is responsible for testing the
intilization of VM. It returns vm_ip
, vm_id
, vmm_port
and return
the status as boolean value.
After the VM is initialized, it is necessary to validate if the VMManager sevice is running or not. It returns the status code.
The implementation code for all above test case scenarios can be found here.