You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2022/12/22 11:00:59 UTC
[cloudstack] branch main updated: Improving code related to the Agent properties (#6348)
This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/main by this push:
new 0fe2e6950e9 Improving code related to the Agent properties (#6348)
0fe2e6950e9 is described below
commit 0fe2e6950e9f94b0099cbb8d1e7f3c245b96f9c9
Author: Paula Oliveira <73...@users.noreply.github.com>
AuthorDate: Thu Dec 22 08:00:49 2022 -0300
Improving code related to the Agent properties (#6348)
Co-authored-by: Paula Zomignani Oliveira <pa...@scclouds.com.br>
Co-authored-by: João Jandre <48...@users.noreply.github.com>
Co-authored-by: GutoVeronezi <da...@scclouds.com.br>
---
agent/conf/agent.properties | 495 ++++----
agent/src/main/java/com/cloud/agent/Agent.java | 3 +-
.../src/main/java/com/cloud/agent/AgentShell.java | 136 ++-
.../src/main/java/com/cloud/agent/IAgentShell.java | 1 -
.../cloud/agent/properties/AgentProperties.java | 712 +++++++++++-
.../properties/AgentPropertiesFileHandler.java | 40 +-
.../test/java/com/cloud/agent/AgentShellTest.java | 308 +++++
.../properties/AgentPropertiesFileHandlerTest.java | 52 +
.../agent/properties/AgentPropertiesTest.java | 43 +
.../com/cloud/resource/ServerResourceBase.java | 131 +--
.../com/cloud/resource/ServerResourceBaseTest.java | 241 ++++
.../hypervisor/kvm/resource/BridgeVifDriver.java | 7 +-
.../hypervisor/kvm/resource/IvsVifDriver.java | 8 +-
.../kvm/resource/LibvirtComputingResource.java | 343 ++----
.../hypervisor/kvm/resource/OvsVifDriver.java | 11 +-
.../kvm/storage/KVMStorageProcessor.java | 11 +-
.../kvm/resource/LibvirtComputingResourceTest.java | 1182 ++++++++++----------
.../kvm/resource/LibvirtVifDriverTest.java | 25 +-
systemvm/debian/opt/cloud/bin/setup/bootstrap.sh | 17 +-
.../main/java/com/cloud/utils/net/NetUtils.java | 58 +-
.../java/com/cloud/utils/net/NetUtilsTest.java | 62 +-
21 files changed, 2655 insertions(+), 1231 deletions(-)
diff --git a/agent/conf/agent.properties b/agent/conf/agent.properties
index e6d8844bda2..29841584595 100644
--- a/agent/conf/agent.properties
+++ b/agent/conf/agent.properties
@@ -17,281 +17,384 @@
# Sample configuration file for CloudStack agent
-# The GUID to identify the agent with, this is mandatory!
-# Generate with "uuidgen"
+# MANDATORY: The GUID to identify the agent with.
+# Generated with "uuidgen"
guid=
-#resource= the java class, which agent load to execute
+# The java class which the agent loads to execute.
resource=com.cloud.hypervisor.kvm.resource.LibvirtComputingResource
-#workers= number of threads running in agent
+# The number of threads running in the agent.
workers=5
-#host= The IP address of management server
+# The IP address of the management server.
host=localhost
-# The time interval in seconds after which agent will check if connected host
-# is the preferred host (the first host in the comma-separated list is preferred
-# one) and will attempt to reconnect to the preferred host when it's connected
-# to one of the secondary/backup hosts. The timer task is scheduled after agent
-# connects to a management server. On connection, it receives admin configured
+# The time interval (in seconds) after which agent will check if the connected host
+# is the preferred host (the first host in the comma-separated list is the preferred
+# one). After that interval, if the agent is connected to one of the secondary/backup hosts,
+# it will attempt to reconnect to the preferred host.
+# The timer task is scheduled after the agent connects to a management server.
+# On connection, it receives admin configured
# cluster-level 'indirect.agent.lb.check.interval' setting that will be used by
-# the agent as the preferred host check interval however the following setting
-# if defined overrides the received value. The value 0 and lb algorithm 'shuffle'
+# the agent as the preferred host check interval, however, if the following setting
+# is defined it will override the received value. The value 0 and lb algorithm 'shuffle'
# disables this background task.
-#host.lb.check.interval=0
+#host.lb.check.interval=
-#port = The port management server listening on, default is 8250
+# The port that the management server is listening on.
port=8250
-#cluster= The cluster which the agent belongs to
+# The cluster which the agent belongs to.
cluster=default
-#pod= The pod which the agent belongs to
+# The pod which the agent belongs to.
pod=default
-#zone= The zone which the agent belongs to
+# The zone which the agent belongs to.
zone=default
-#public.network.device= the public nic device
-# if this is commented, it is autodetected on service startup
-# public.network.device=cloudbr0
+# The public NIC device.
+# If this is commented, it will be autodetected on service startup.
+#public.network.device=cloudbr0
-#private.network.device= the private nic device
-# if this is commented, it is autodetected on service startup
-# private.network.device=cloudbr1
+# The private NIC device.
+# If this is commented, it will be autodetected on service startup.
+#private.network.device=cloudbr1
-#guest.network.device= the guest nic device
-# if this is commented, the private nic device will be used
+# The guest NIC device.
+# If this is commented, the value of the private NIC device will be used.
+#guest.network.device=
-# local storage path, by default, it's /var/lib/libvirt/images/
+# Local storage path. Multiple values can be entered and separated by commas.
#local.storage.path=/var/lib/libvirt/images/
-# Qemu socket path, directory where Qemu sockets are placed.
-# These sockets are for the Qemu Guest Agent and SSVM privisioning
-# Make sure that AppArmor or SELinux allow libvirt to write there
+# Directory where Qemu sockets are placed.
+# These sockets are for the Qemu Guest Agent and SSVM provisioning.
+# Make sure that AppArmor or SELinux allow libvirt to write there.
#qemu.sockets.path=/var/lib/libvirt/qemu
-# The UUID for the local storage pool, this is mandatory!
-# Generate with "uuidgen"
+# MANDATORY: The UUID for the local storage pool. Multiple values can be entered and separated by commas.
+# Generated with "uuidgen".
local.storage.uuid=
-# Location for KVM scripts
+# Location for KVM virtual router scripts.
+# The path defined in this property is relative to the directory "/usr/share/cloudstack-common/".
domr.scripts.dir=scripts/network/domr/kvm
-# the timeout for time-consuming operations, such as create/copy snapshot
+# The timeout (in ms) for time-consuming operations, such as create/copy a snapshot.
#cmds.timeout=7200
-# set the vm migrate speed, by default, it will try to guess the speed of the guest network
-# In MegaBytes per second
-#vm.migrate.speed=0
+# This parameter sets the VM migration speed.
+# By default, it will try to guess the speed of the guest network and consume all possible bandwidth.
+# The default value is -1, which means that the agent will use all possible bandwidth.
+# When entering a value, make sure to enter it in megabytes per second.
+#vm.migrate.speed=-1
-# set target downtime at end of livemigration, the 'hiccup' for final copy. Higher numbers
-# make livemigration easier, lower numbers may cause migration to never complete. Less than 1
-# means hypervisor default (20ms).
-#vm.migrate.downtime=0
+# Sets target downtime (in ms) at end of livemigration, the 'hiccup' for final copy.
+# Higher numbers make livemigration easier, lower numbers may cause migration to never complete.
+# Less than 1 means hypervisor default (20ms).
+#vm.migrate.downtime=-1
-# Busy VMs may never finish migrating, depending on environment. When its available, we will
-# want to add support for autoconvergence migration flag which should fix this. Set an upper
-# limit in milliseconds for how long live migration should wait, at which point VM is paused and
-# migration will finish quickly. Less than 1 means disabled.
-#vm.migrate.pauseafter=0
+# Busy VMs may never finish migrating, depending on environment.
+# Therefore, if configured, this option will pause the VM after the time entered (in ms) to force the migration to finish.
+# Less than 1 means disabled.
+#vm.migrate.pauseafter=-1
-# Time (in seconds) to wait for VM migrate finish. Less than 1 means disabled.
-# If vm migration is not finished in the time, the vm job will be cancelled by libvirt.
+# Time (in seconds) to wait for VM migraton to finish. Less than 1 means disabled.
+# If the VM migration is not finished in the time, the VM job will be cancelled by libvirt.
# It will be configured by cloudstack management server when cloudstack agent connects.
-# please change the global setting 'migratewait' if needed (default value: 3600)
-#vm.migrate.wait=0
+# please change the global setting 'migratewait' if needed (migratewait default value: 3600).
+#vm.migrate.wait=-1
+# ---------------- AGENT HOOKS -----------------
# Agent hooks is the way to override default agent behavior to extend the functionality without excessive coding
-# for a custom deployment. The first hook promoted is libvirt-vm-xml-transformer which allows provider to modify
-# VM XML specification before send to libvirt. Hooks are implemented in Groovy and must be implemented in the way
-# to keep default CS behaviour is something goes wrong.
-# All hooks are located in a special directory defined in 'agent.hooks.basedir'
-#
+# for a custom deployment.
+# There are 3 arguments needed for the hook to be called: the base directory (defined in agent.hooks.basedir),
+# the name of the script that is located in the base directory (defined in agent.hooks.*.script)
+# and the method that is going to be called on the script (defined in agent.hooks.*.method).
+# These properties are detailed below.
+# Hooks are implemented in Groovy and must be implemented in a way
+# that keeps default CS behavior if something goes wrong.
+
+# All hooks are located in a special directory defined in 'agent.hooks.basedir'.
# agent.hooks.basedir=/etc/cloudstack/agent/hooks
-# every hook has two major attributes - script name, specified in 'agent.hooks.*.script' and method name
+# Every hook has two major attributes - script name, specified in 'agent.hooks.*.script' and method name
# specified in 'agent.hooks.*.method'.
-# Libvirt XML transformer hook does XML-to-XML transformation which provider can use to add/remove/modify some
-# sort of attributes in Libvirt XML domain specification.
-# agent.hooks.libvirt_vm_xml_transformer.script=libvirt-vm-xml-transformer.groovy
-# agent.hooks.libvirt_vm_xml_transformer.method=transform
-#
-# The hook is called right after libvirt successfully launched VM
-# agent.hooks.libvirt_vm_on_start.script=libvirt-vm-state-change.groovy
-# agent.hooks.libvirt_vm_on_start.method=onStart
-#
-# The hook is called right after libvirt successfully stopped VM
-# agent.hooks.libvirt_vm_on_stop.script=libvirt-vm-state-change.groovy
-# agent.hooks.libvirt_vm_on_stop.method=onStop
-#
-
-# set the type of bridge used on the hypervisor, this defines what commands the resource
-# will use to setup networking. Currently supported NATIVE, OPENVSWITCH
-#network.bridge.type=native
+# Libvirt XML transformer hook does XML-to-XML transformation, which allows the provider to modify
+# VM XML specification before is sent to libvirt.
+# The provider can use this to add/remove/modify some sort of attributes in Libvirt XML domain specification.
+#agent.hooks.libvirt_vm_xml_transformer.script=libvirt-vm-xml-transformer.groovy
+#agent.hooks.libvirt_vm_xml_transformer.method=transform
-# set the driver used to plug and unplug nics from the bridges
-# a sensible default will be selected based on the network.bridge.type but can
-# be overridden here.
-# native = com.cloud.hypervisor.kvm.resource.BridgeVifDriver
-# openvswitch = com.cloud.hypervisor.kvm.resource.OvsVifDriver
-#libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.BridgeVifDriver
+# The hook is called right after libvirt successfully launched the VM.
+#agent.hooks.libvirt_vm_on_start.script=libvirt-vm-state-change.groovy
+#agent.hooks.libvirt_vm_on_start.method=onStart
-# Set DPDK Support on OpenVswitch
-#openvswitch.dpdk.enabled=true
-#openvswitch.dpdk.ovs.path=/var/run/openvswitch
+# The hook is called right after libvirt successfully stopped the VM.
+#agent.hooks.libvirt_vm_on_stop.script=libvirt-vm-state-change.groovy
+#agent.hooks.libvirt_vm_on_stop.method=onStop
+# ---------------- END AGENT HOOKS ---------------
+
+# Sets the type of bridge used on the hypervisor. This defines what commands the resource
+# will use to setup networking.
+# Possible Values: native | openvswitch
+#network.bridge.type=native
-# set the hypervisor type, values are: kvm, lxc
+# Sets the driver used to plug and unplug NICs from the bridges.
+# A sensible default value will be selected based on the network.bridge.type but can
+# be overridden here.
+# Also used to enable direct networking in libvirt (see properties below).
+# Default value when network.bridge.type as native = com.cloud.hypervisor.kvm.resource.BridgeVifDriver
+# Default value when network.bridge.type as openvswitch = com.cloud.hypervisor.kvm.resource.OvsVifDriver
+#libvirt.vif.driver=
+
+# Settings to enable direct networking in libvirt.
+# Should not be used on hosts that run system VMs.
+# Possible values for mode: private | bridge | vepa
+#libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.DirectVifDriver
+#network.direct.source.mode=private
+#network.direct.device=eth0
+
+# Sets DPDK Support on OpenVswitch.
+#openvswitch.dpdk.enabled=false
+#openvswitch.dpdk.ovs.path=
+
+# Sets the hypervisor type.
+# Possible values: kvm | lxc
hypervisor.type=kvm
-# This parameter specifies a directory on the host local storage for temporary storing direct download templates
+# This parameter specifies a directory on the host local storage for temporary storing direct download templates.
#direct.download.temporary.download.location=/var/lib/libvirt/images
-# This parameter specifies a directory on the host local storage for creating and hosting the config drives
+# This parameter specifies a directory on the host local storage for creating and hosting the config drives.
#host.cache.location=/var/cache/cloud
-# set the rolling maintenance hook scripts directory
-#rolling.maintenance.hooks.dir=/etc/cloudstack/agent/hooks.d
+# Sets the rolling maintenance hook scripts directory.
+# Default is null, however, can be used as /etc/cloudstack/agent/hooks.d
+#rolling.maintenance.hooks.dir=
-# disable the rolling maintenance service execution
-#rolling.maintenance.service.executor.disabled=true
+# Disables the rolling maintenance service execution.
+#rolling.maintenance.service.executor.disabled=false
-# set the hypervisor URI. Usually there is no need for changing this
+# Sets the hypervisor URI. If null (default), the value defaults according the hypervisor.type:
# For KVM: qemu:///system
# For LXC: lxc:///
-# hypervisor.uri=qemu:///system
-
-# settings to enable direct networking in libvirt, should not be used
-# on hosts that run system vms, values for mode are: private, bridge, vepa
-# libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.DirectVifDriver
-# network.direct.source.mode=private
-# network.direct.device=eth0
-
-# setting to enable the cpu model to kvm guest globally.
-# three option:custom,host-model and host-passthrough.
-# custom - user custom the CPU model which specified by guest.cpu.model.
-# host-model - identify the named CPU model which most closely matches the host,
-# and then request additional CPU flags to complete the match. This should give
-# close to maximum functionality/performance, which maintaining good
+#hypervisor.uri=
+
+# Setting to enable the CPU model to KVM guest globally.
+# Possible values: custom | host-model | host-passthrough
+# - custom: user customs the CPU model, which is specified by property guest.cpu.model.
+# - host-model: identifies the named CPU model which most closely matches the host,
+# and then requests additional CPU flags to complete the match. This should give
+# close to maximum functionality/performance, which maintains good
# reliability/compatibility if the guest is migrated to another host with slightly different host CPUs.
-# host-passthrough - tell KVM to passthrough the host CPU with no modifications.
-# The difference to host-model, instead of just matching feature flags,
+# - host-passthrough: tells KVM to passthrough the host CPU with no modifications.
+# It is different from host-model because instead of just matching feature flags,
# every last detail of the host CPU is matched. This gives absolutely best performance,
# and can be important to some apps which check low level CPU details,
-# but it comes at a cost wrt migration. The guest can only be migrated to
+# but it comes at a cost with migration. The guest can only be migrated to
# an exactly matching host CPU.
-#
-# guest.cpu.mode=custom|host-model|host-passthrough
-# This param is only valid if guest.cpu.mode=custom,
-# for examples:"Conroe" "Penryn", "Nehalem", "Westmere", "pentiumpro" and so
-# on,run virsh capabilities for more details.
-# guest.cpu.model=
-#
-# This param will set the CPU architecture for the domain override what
-# the management server would send
+# If null (default), libvirt defaults to custom
+#guest.cpu.mode=
+
+# Custom CPU model. This param is only valid if guest.cpu.mode=custom.
+# Possible values:"Conroe" | "Penryn" | "Nehalem" | "Westmere" | "pentiumpro" etc.
+# Run virsh capabilities for more details.
+#guest.cpu.model=
+
+# This param will set the CPU architecture for the domain to override what
+# the management server would send.
# In case of arm64 (aarch64), this will change the machine type to 'virt' and
# adds a SCSI and a USB controller in the domain xml.
-# guest.cpu.arch=x86_64|aarch64
-#
-# This param will require CPU features on the <cpu> section
-# guest.cpu.features=vmx vme
-#
-# vm.memballoon.disable=true
-# Disable memory ballooning on vm guests for overcommit, by default overcommit
-# feature enables balloon and sets currentMemory to a minimum value.
-#
+# Possible values: x86_64 | aarch64
+# If null (default), defaults to the VM's OS architecture
+#guest.cpu.arch=
+
+# This param will require CPU features on the CPU section.
+# The features listed in this property must be separated by a blank space (e.g.: vmx vme)
+#guest.cpu.features=
+
+# Disables memory ballooning on VM guests for overcommit.
+# By default overcommit feature enables balloon and sets currentMemory to a minimum value.
+#vm.memballoon.disable=false
+
# The time interval (in seconds) at which the balloon driver will get memory stats updates.
# This is equivalent to Libvirt's --period parameter when using the dommemstat command.
# vm.memballoon.stats.period=0
-#
-# vm.diskactivity.checkenabled=false
+
# Set to true to check disk activity on VM's disks before starting a VM. This only applies
# to QCOW2 files, and ensures that there is no other running instance accessing
-# the file before starting. It works by checking the modify time against the current time,
-# so care must be taken to ensure the cluster has time synced, otherwise VMs may fail to start.
-#
-# vm.diskactivity.checktimeout_s=120
-# Timeout for giving up on waiting for VM's disk files to become inactive. Hitting
-# this timeout will result in failure to start VM.
-#
-# vm.diskactivity.inactivetime_ms=30000
-# This is the length of time that the disk needs to be inactive in order to pass the check.
-# This means current time minus mtime of disk file needs to be greater than this number.
+# the file before starting. It works by checking the modified time against the current time,
+# so care must be taken to ensure that the cluster's time is synchronized, otherwise VMs may fail to start.
+#vm.diskactivity.checkenabled=false
+
+# Timeout (in seconds) for giving up on waiting for VM's disk files to become inactive.
+# Hitting this timeout will result in failure to start VM.
+# Value must be > 0.
+#vm.diskactivity.checktimeout_s=120
+
+# This is the length of time (in ms) that the disk needs to be inactive in order to pass the check.
+# This means current time minus time of disk file needs to be greater than this number.
# It also has the side effect of setting the minimum threshold between a stop and start of
# a given VM.
-#
-# kvmclock.disable=false
-# Some newer linux kernels are incapable of reliably migrating vms with kvmclock
-# This is a workaround for the bug, admin can set this to true per-host
-#
-# vm.rng.enable=false
-# This enabled the VirtIO Random Number Generator device for guests.
-#
-# vm.rng.model=random
+#vm.diskactivity.inactivetime_ms=30000
+
+# Some newer linux kernels are incapable of reliably migrating VMs with KVMclock.
+# This is a workaround for the bug, admin can set this to true per-host.
+#kvmclock.disable=false
+
+# This enables the VirtIO Random Number Generator (RNG) device for guests.
+#vm.rng.enable=false
+
# The model of VirtIO Random Number Generator (RNG) to present to the Guest.
# Currently only 'random' is supported.
-#
-# vm.rng.path=/dev/random
+#vm.rng.model=random
+
# Local Random Number Device Generator to use for VirtIO RNG for Guests.
-# This is usually /dev/random, but per platform this might be different
-#
-# vm.rng.rate.bytes=2048
+# This is usually /dev/random, but it might be different per platform.
+#vm.rng.path=/dev/random
+
# The amount of bytes the Guest may request/obtain from the RNG in the period
-# specified below.
-#
-# vm.rng.rate.period=1000
+# specified in the property vm.rng.rate.period.
+#vm.rng.rate.bytes=2048
+
# The number of milliseconds in which the guest is allowed to obtain the bytes
-# specified above.
-#
-# router.aggregation.command.each.timeout=600
-# timeout value for aggregation commands send to virtual router
-#
-# host.overcommit.mem.mb = 0
-# allows to increase amount of ram available on host virtually to utilize Zswap, KSM features
-# and modern fast SSD/3D XPoint devices. Specified amount of MBs is added to the memory agent
-# reports to the Management Server
-# Default: 0
-#
-# host.reserved.mem.mb = 0
-# How much host memory to reserve for non-allocation.
+# specified in the property vm.rng.rate.bytes.
+#vm.rng.rate.period=1000
+
+# Timeout value for aggregation commands to be sent to the virtual router (in seconds).
+#router.aggregation.command.each.timeout=
+
+# Allows virtually increase the amount of RAM (in MB) available on the host.
+# This property can be useful if the host uses Zswap, KSM features and other memory compressing technologies.
+# For example: if the host has 2GB of RAM and this property is set to 2048, the amount of RAM of the host will be read as 4GB.
+#host.overcommit.mem.mb=0
+
+# How much host memory (in MB) to reserve for non-allocation.
# A useful parameter if a node uses some other software that requires memory,
-# or in case that OOM Killer kicks in sometimes.
-# If this parameter is used, host.overcommit.mem.mb must be set to 0.
-# Default value: 0
-#
-# vm.watchdog.model=i6300esb
-# The model of Watchdog timer to present to the Guest
+# or in case that OOM Killer kicks in.
+# If this parameter is used, property host.overcommit.mem.mb must be set to 0.
+#host.reserved.mem.mb=1024
+
+# The model of Watchdog timer to present to the Guest.
# For all models refer to the libvirt documentation.
-# Recommend value is: i6300esb
-#
-# vm.watchdog.action=none
-# Action to take when the Guest/Instance is no longer notifying the Watchdog
-# timer.
+#vm.watchdog.model=i6300esb
+
+# Action to take when the Guest/Instance is no longer notifying the Watchdog timer.
# For all actions refer to the libvirt documentation.
-# Recommended values are: none, reset and poweroff.
-#
+# Possible values: none | reset | poweroff
+#vm.watchdog.action=none
+
+# Automatically clean up iSCSI sessions not attached to any VM.
+# Should be enabled for users using managed storage (for example solidfire).
+# Should be disabled for users with unmanaged iSCSI connections on their hosts.
iscsi.session.cleanup.enabled=false
-# Automatically clean up iscsi sessions not attached to any VM.
-# Should be enabled for users using managed storage for example solidfire.
-# Should be disabled for users with unmanaged iscsi connections on their hosts
-# This parameter specifies the heartbeat update timeout in ms; The default value is 60000ms (1 min).
+# The heartbeat update timeout (in ms).
# Depending on the use case, this timeout might need increasing/decreasing.
-# heartbeat.update.timeout=60000
+#heartbeat.update.timeout=60000
-# This parameter specifies the timeout in seconds to retrieve the target's domain id when migrating a VM with KVM.
-# vm.migrate.domain.retrieve.timeout=10
+# The timeout (in seconds) to retrieve the target's domain id when migrating a VM with KVM.
+#vm.migrate.domain.retrieve.timeout=10
# This parameter specifies if the host must be rebooted when something goes wrong with the heartbeat.
-# reboot.host.and.alert.management.on.heartbeat.timeout=true
-
-# Enable manually setting CPU's topology on KVM's VM.
-# enable.manually.setting.cpu.topology.on.kvm.vm=true
-
-# Manually set the host CPU MHz, in cases where CPU scaling support detected value is wrong
-# host.cpu.manual.speed.mhz=0
-
-# Enable/disable IO driver for Qemu (in case it is not set CloudStack can also detect if its supported by qemu)
-# enable.io.uring=true
+#reboot.host.and.alert.management.on.heartbeat.timeout=true
+
+# Enables manually setting CPU's topology on KVM's VM.
+#enable.manually.setting.cpu.topology.on.kvm.vm=true
+
+# Manually sets the host CPU MHz, in cases where CPU scaling support detects the value is wrong.
+#host.cpu.manual.speed.mhz=0
+
+# Enables/disables the IO driver for Qemu (in case it is not set CloudStack can also detect if it is supported by Qemu).
+#enable.io.uring=
+
+# Defines the location for Hypervisor scripts.
+# The path defined in this property is relative.
+# To locate the script, ACS first tries to concatenate
+# the property path with "/usr/share/cloudstack-agent/lib/".
+# If it fails, it will test each folder of the path,
+# decreasing one by one, until it reaches root.
+# If the script is not found, ACS will repeat the same
+# steps concatenating the property path with "/usr/share/cloudstack-common/".
+# The path defined in this property is relative
+# to the directory "/usr/share/cloudstack-common/".
+#hypervisor.scripts.dir=scripts/vm/hypervisor
+
+# Defines the location for KVM scripts.
+# The path defined in this property is relative.
+# To locate the script, ACS first tries to concatenate
+# the property path with "/usr/share/cloudstack-agent/lib/".
+# If it fails, it will test each folder of the path,
+# decreasing one by one, until it reaches root.
+# If the script is not found, ACS will repeat the same
+# steps concatenating the property path with "/usr/share/cloudstack-common/".
+# The path defined in this property is relative
+# to the directory "/usr/share/cloudstack-common/".
+#kvm.scripts.dir=scripts/vm/hypervisor/kvm
+
+# Specifies start MAC address for private IP range.
+#private.macaddr.start=00:16:3e:77:e2:a0
+
+# Specifies start IP address for private IP range.
+#private.ipaddr.start=192.168.166.128
+
+# Defines Local Bridge Name.
+#private.bridge.name=
+
+# Defines private network name.
+#private.network.name=
+
+# Defines the location for network scripts.
+# The path defined in this property is relative.
+# To locate the script, ACS first tries to concatenate
+# the property path with "/usr/share/cloudstack-agent/lib/".
+# If it fails, it will test each folder of the path,
+# decreasing one by one, until it reaches root.
+# If the script is not found, ACS will repeat the same
+# steps concatenating the property path with "/usr/share/cloudstack-common/".
+# The path defined in this property is relative
+# to the directory "/usr/share/cloudstack-common/".
+#network.scripts.dir=scripts/vm/network/vnet
+
+# Defines the location for storage scripts.
+# The path defined in this property is relative.
+# To locate the script, ACS first tries to concatenate
+# the property path with "/usr/share/cloudstack-agent/lib/".
+# If it fails, it will test each folder of the path,
+# decreasing one by one, until it reaches root.
+# If the script is not found, ACS will repeat the same
+# steps concatenating the property path with "/usr/share/cloudstack-common/".
+# The path defined in this property is relative
+# to the directory "/usr/share/cloudstack-common/".
+#storage.scripts.dir=scripts/storage/qcow2
+
+# Time (in seconds) to wait for the VM to shutdown gracefully.
+# If the time is exceeded shutdown will be forced.
+#stop.script.timeout=120
+
+# Definition of VMs video model type.
+#vm.video.hardware=
+
+# Definition of VMs video, specifies the amount of RAM in kibibytes (blocks of 1024 bytes).
+#vm.video.ram=0
+
+# System VM ISO path.
+#systemvm.iso.path=
+
+# If set to "true", allows override of the properties: private.macaddr.start, private.ipaddr.start, private.ipaddr.end.
+#developer=false
+
+# Can only be used if property developer = true. This property is used to define the link local bridge name and private network name.
+#instance=
+
+# Shows the path to the base directory in which NFS servers are going to be mounted.
+#mount.path=/mnt
+
+# Port listened by the console proxy.
+#consoleproxy.httpListenPort=443
+
+#ping.retries=5
diff --git a/agent/src/main/java/com/cloud/agent/Agent.java b/agent/src/main/java/com/cloud/agent/Agent.java
index b0028c148fb..e9213ca9b8c 100644
--- a/agent/src/main/java/com/cloud/agent/Agent.java
+++ b/agent/src/main/java/com/cloud/agent/Agent.java
@@ -27,6 +27,7 @@ import java.net.UnknownHostException;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
@@ -179,7 +180,7 @@ public class Agent implements HandlerFactory, IAgentControl {
_id = value != null ? Long.parseLong(value) : null;
s_logger.info("id is " + (_id != null ? _id : ""));
- final Map<String, Object> params = PropertiesUtil.toMap(_shell.getProperties());
+ final Map<String, Object> params = new HashMap<>();
// merge with properties from command line to let resource access command line parameters
for (final Map.Entry<String, Object> cmdLineProp : _shell.getCmdLineProperties().entrySet()) {
diff --git a/agent/src/main/java/com/cloud/agent/AgentShell.java b/agent/src/main/java/com/cloud/agent/AgentShell.java
index c36656200a5..ef042496a37 100644
--- a/agent/src/main/java/com/cloud/agent/AgentShell.java
+++ b/agent/src/main/java/com/cloud/agent/AgentShell.java
@@ -19,9 +19,10 @@ package com.cloud.agent;
import com.cloud.agent.Agent.ExitStatus;
import com.cloud.agent.dao.StorageComponent;
import com.cloud.agent.dao.impl.PropertiesStorage;
+import com.cloud.agent.properties.AgentProperties;
+import com.cloud.agent.properties.AgentPropertiesFileHandler;
import com.cloud.resource.ServerResource;
import com.cloud.utils.LogUtils;
-import com.cloud.utils.NumbersUtil;
import com.cloud.utils.ProcessUtil;
import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.backoff.BackoffAlgorithm;
@@ -31,6 +32,7 @@ import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
import org.apache.commons.daemon.DaemonInitException;
import org.apache.commons.lang.math.NumberUtils;
+import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;
@@ -74,6 +76,7 @@ public class AgentShell implements IAgentShell, Daemon {
private String hostToConnect;
private String connectedHost;
private Long preferredHostCheckInterval;
+ protected AgentProperties agentProperties = new AgentProperties();
public AgentShell() {
}
@@ -265,75 +268,83 @@ public class AgentShell implements IAgentShell, Daemon {
}
}
- if (port == null) {
- port = getProperty(null, "port");
- }
+ setHost(host);
- _port = NumberUtils.toInt(port, 8250);
+ _guid = getGuid(guid);
+ _properties.setProperty(AgentProperties.GUID.getName(), _guid);
- _proxyPort = NumberUtils.toInt(getProperty(null, "consoleproxy.httpListenPort"), 443);
+ _port = getPortOrWorkers(port, AgentProperties.PORT);
+ _workers = getWorkers(workers);
+ _zone = getZoneOrPod(zone, AgentProperties.ZONE);
+ _pod = getZoneOrPod(pod, AgentProperties.POD);
- if (workers == null) {
- workers = getProperty(null, "workers");
- }
+ _proxyPort = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CONSOLEPROXY_HTTPLISTENPORT);
+ _pingRetries = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.PING_RETRIES);
+ preferredHostCheckInterval = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_LB_CHECK_INTERVAL);
- _workers = NumberUtils.toInt(workers, 5);
- if (_workers <= 0) {
- _workers = 5;
- }
+ return true;
+ }
+ protected void setHost(String host) throws ConfigurationException {
if (host == null) {
- host = getProperty(null, "host");
+ host = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST);
}
- if (host == null) {
- host = "localhost";
+ if (isValueStartingAndEndingWithAtSign(host)) {
+ throw new ConfigurationException(String.format("Host [%s] is not configured correctly.", host));
}
setHosts(host);
+ }
- if (zone != null)
- _zone = zone;
- else
- _zone = getProperty(null, "zone");
- if (_zone == null || (_zone.startsWith("@") && _zone.endsWith("@"))) {
- _zone = "default";
+ protected boolean isValueStartingAndEndingWithAtSign(String value) {
+ return value.startsWith("@") && value.endsWith("@");
+ }
+
+ protected String getGuid(String guid) throws ConfigurationException {
+ guid = StringUtils.defaultString(guid, AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUID));
+ if (guid != null) {
+ return guid;
}
- if (pod != null)
- _pod = pod;
- else
- _pod = getProperty(null, "pod");
- if (_pod == null || (_pod.startsWith("@") && _pod.endsWith("@"))) {
- _pod = "default";
+ if (BooleanUtils.isFalse(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.DEVELOPER))) {
+ throw new ConfigurationException("Unable to find the guid");
+ }
+
+ return UUID.randomUUID().toString();
+ }
+
+ protected String getZoneOrPod(String zoneOrPod, AgentProperties.Property<String> property) {
+ String value = zoneOrPod;
+
+ if (value == null) {
+ value = AgentPropertiesFileHandler.getPropertyValue(property);
}
- if (_host == null || (_host.startsWith("@") && _host.endsWith("@"))) {
- throw new ConfigurationException("Host is not configured correctly: " + _host);
+ if (isValueStartingAndEndingWithAtSign(value)) {
+ value = property.getDefaultValue();
}
- final String retries = getProperty(null, "ping.retries");
- _pingRetries = NumbersUtil.parseInt(retries, 5);
+ return value;
+ }
- String value = getProperty(null, "developer");
- boolean developer = Boolean.parseBoolean(value);
+ protected int getWorkers(String workersString) {
+ AgentProperties.Property<Integer> propertyWorkers = agentProperties.getWorkers();
+ int workers = getPortOrWorkers(workersString, propertyWorkers);
- if (guid != null)
- _guid = guid;
- else
- _guid = getProperty(null, "guid");
- if (_guid == null) {
- if (!developer) {
- throw new ConfigurationException("Unable to find the guid");
- }
- _guid = UUID.randomUUID().toString();
- _properties.setProperty("guid", _guid);
+ if (workers <= 0) {
+ workers = propertyWorkers.getDefaultValue();
}
- String val = getProperty(null, preferredHostIntervalKey);
- preferredHostCheckInterval = StringUtils.isEmpty(val) ? null : Long.valueOf(val);
+ return workers;
+ }
- return true;
+ protected int getPortOrWorkers(String portOrWorkers, AgentProperties.Property<Integer> property) {
+ if (portOrWorkers == null) {
+ return AgentPropertiesFileHandler.getPropertyValue(property);
+ }
+
+ return NumberUtils.toInt(portOrWorkers, property.getDefaultValue());
}
@Override
@@ -398,7 +409,7 @@ public class AgentShell implements IAgentShell, Daemon {
}
private void launchAgent() throws ConfigurationException {
- String resourceClassNames = getProperty(null, "resource");
+ String resourceClassNames = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.RESOURCE);
s_logger.trace("resource=" + resourceClassNames);
if (resourceClassNames != null) {
launchAgentFromClassInfo(resourceClassNames);
@@ -414,25 +425,15 @@ public class AgentShell implements IAgentShell, Daemon {
Class<?> impl;
try {
impl = Class.forName(name);
- final Constructor<?> constructor = impl.getDeclaredConstructor();
+ Constructor<?> constructor = impl.getDeclaredConstructor();
constructor.setAccessible(true);
ServerResource resource = (ServerResource)constructor.newInstance();
launchNewAgent(resource);
- } catch (final ClassNotFoundException e) {
- throw new ConfigurationException("Resource class not found: " + name + " due to: " + e.toString());
- } catch (final SecurityException e) {
- throw new ConfigurationException("Security exception when loading resource: " + name + " due to: " + e.toString());
- } catch (final NoSuchMethodException e) {
- throw new ConfigurationException("Method not found exception when loading resource: " + name + " due to: " + e.toString());
- } catch (final IllegalArgumentException e) {
- throw new ConfigurationException("Illegal argument exception when loading resource: " + name + " due to: " + e.toString());
- } catch (final InstantiationException e) {
- throw new ConfigurationException("Instantiation exception when loading resource: " + name + " due to: " + e.toString());
- } catch (final IllegalAccessException e) {
- throw new ConfigurationException("Illegal access exception when loading resource: " + name + " due to: " + e.toString());
- } catch (final InvocationTargetException e) {
- throw new ConfigurationException("Invocation target exception when loading resource: " + name + " due to: " + e.toString());
- }
+ } catch (final ClassNotFoundException | SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException |
+ IllegalAccessException | InvocationTargetException e) {
+ ConfigurationException configurationException = new ConfigurationException(String.format("Error while creating Agent with class [%s].", name));
+ configurationException.setRootCause(e);
+ throw configurationException; }
}
}
@@ -492,7 +493,7 @@ public class AgentShell implements IAgentShell, Daemon {
String instance = getProperty(null, "instance");
if (instance == null) {
- if (Boolean.parseBoolean(getProperty(null, "developer"))) {
+ if (BooleanUtils.isTrue(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.DEVELOPER))) {
instance = UUID.randomUUID().toString();
} else {
instance = "";
@@ -516,13 +517,8 @@ public class AgentShell implements IAgentShell, Daemon {
s_logger.debug("[ignored] AgentShell was interrupted.");
}
- } catch (final ConfigurationException e) {
- s_logger.error("Unable to start agent: " + e.getMessage());
- System.out.println("Unable to start agent: " + e.getMessage());
- System.exit(ExitStatus.Configuration.value());
} catch (final Exception e) {
s_logger.error("Unable to start agent: ", e);
- System.out.println("Unable to start agent: " + e.getMessage());
System.exit(ExitStatus.Error.value());
}
}
diff --git a/agent/src/main/java/com/cloud/agent/IAgentShell.java b/agent/src/main/java/com/cloud/agent/IAgentShell.java
index 5d389a07041..2dd08fffd45 100644
--- a/agent/src/main/java/com/cloud/agent/IAgentShell.java
+++ b/agent/src/main/java/com/cloud/agent/IAgentShell.java
@@ -26,7 +26,6 @@ import com.cloud.utils.backoff.BackoffAlgorithm;
public interface IAgentShell {
String hostLbAlgorithmSeparator = "@";
- String preferredHostIntervalKey = "host.lb.check.interval";
Map<String, Object> getCmdLineProperties();
diff --git a/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java b/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java
index 9f84bb572db..f7c9f1a9025 100644
--- a/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java
+++ b/agent/src/main/java/com/cloud/agent/properties/AgentProperties.java
@@ -24,35 +24,374 @@ package com.cloud.agent.properties;
* @param <T> type of the default value.
*/
public class AgentProperties{
+ private static final String DEFAULT = "default";
/**
- * Heartbeat update timeout. <br>
- * Data type: int. <br>
- * Default value: 60000 (ms).
+ * MANDATORY: The GUID to identify the agent with.<br>
+ * Generated with "uuidgen".<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
*/
- public static final Property<Integer> HEARTBEAT_UPDATE_TIMEOUT = new Property<Integer>("heartbeat.update.timeout", 60000);
+ public static final Property<String> GUID = new Property<>("guid", null, String.class);
/**
- * The timeout in seconds to retrieve the target's domain id when migrating a VM with KVM. <br>
- * Data type: int. <br>
- * Default value: 10 (sec).
+ * The java class which the agent loads to execute.<br>
+ * Data type: String.<br>
+ * Default value: <code>com.cloud.hypervisor.kvm.resource.LibvirtComputingResource</code>
*/
- public static final Property<Integer> VM_MIGRATE_DOMAIN_RETRIEVE_TIMEOUT = new Property<Integer>("vm.migrate.domain.retrieve.timeout", 10);
+ public static final Property<String> RESOURCE = new Property<>("resource", "com.cloud.hypervisor.kvm.resource.LibvirtComputingResource");
/**
- * Reboot host and alert management on heartbeat timeout. <br>
- * Data type: boolean.<br>
- * Default value: true.
+ * The number of threads running in the agent.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>5</code>
*/
- public static final Property<Boolean> REBOOT_HOST_AND_ALERT_MANAGEMENT_ON_HEARTBEAT_TIMEOUT
- = new Property<Boolean>("reboot.host.and.alert.management.on.heartbeat.timeout", true);
+ protected final Property<Integer> workers = new Property<>("workers", 5);
+
+ /**
+ * The IP address of the management server.<br>
+ * Data type: String.<br>
+ * Default value: <code>localhost</code>
+ */
+ public static final Property<String> HOST = new Property<>("host", "localhost");
+
+ /**
+ * The time interval (in seconds) after which the agent will check if the connected host is the preferred host.<br>
+ * After that interval, if the agent is connected to one of the secondary/backup hosts, it will attempt to reconnect to the preferred host.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<Long> HOST_LB_CHECK_INTERVAL = new Property<>("host.lb.check.interval", null, Long.class);
+
+ /**
+ * The port that the management server is listening on.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>8250</code>
+ */
+ public static final Property<Integer> PORT = new Property<>("port", 8250);
+
+ /**
+ * The cluster which the agent belongs to.<br>
+ * Data type: String.<br>
+ * Default value: <code>default</code>
+ */
+ public static final Property<String> CLUSTER = new Property<>("cluster", DEFAULT);
+
+ /**
+ * The pod which the agent belongs to.<br>
+ * Data type: String.<br>
+ * Default value: <code>default</code>
+ */
+ public static final Property<String> POD = new Property<>("pod", DEFAULT);
+
+ /**
+ * The zone which the agent belongs to.<br>
+ * Data type: String.<br>
+ * Default value: <code>default</code>
+ */
+ public static final Property<String> ZONE = new Property<>("zone", DEFAULT);
+
+ /**
+ * Public NIC device. If this property is commented, it will be autodetected on service startup.<br>
+ * Data type: String.<br>
+ * Default value: <code>cloudbr0</code>
+ */
+ public static final Property<String> PUBLIC_NETWORK_DEVICE = new Property<>("public.network.device", "cloudbr0");
+
+ /**
+ * Private NIC device. If this property is commented, it will be autodetected on service startup.<br>
+ * Data type: String.<br>
+ * Default value: <code>cloudbr1</code>
+ */
+ public static final Property<String> PRIVATE_NETWORK_DEVICE = new Property<>("private.network.device", "cloudbr1");
+
+ /**
+ * Guest NIC device. If this property is commented, the value of the private NIC device will be used.<br>
+ * Data type: String.<br>
+ * Default value: the private NIC device value.
+ */
+ public static final Property<String> GUEST_NETWORK_DEVICE = new Property<>("guest.network.device", null, String.class);
+
+ /**
+ * Local storage path.<br>
+ * This property allows multiple values to be entered in a single String. The differente values must be separated by commas.<br>
+ * Data type: String.<br>
+ * Default value: <code>/var/lib/libvirt/images/</code>
+ */
+ public static final Property<String> LOCAL_STORAGE_PATH = new Property<>("local.storage.path", "/var/lib/libvirt/images/");
+
+ /**
+ * Directory where Qemu sockets are placed.<br>
+ * These sockets are for the Qemu Guest Agent and SSVM provisioning.<br>
+ * Make sure that AppArmor or SELinux allows Libvirt to write there.<br>
+ * Data type: String.<br>
+ * Default value: <code>/var/lib/libvirt/qemu</code>
+ */
+ public static final Property<String> QEMU_SOCKETS_PATH = new Property<>("qemu.sockets.path", "/var/lib/libvirt/qemu");
+
+ /**
+ * MANDATORY: The UUID for the local storage pool.<br>
+ * This property allows multiple values to be entered in a single String. The differente values must be separated by commas.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> LOCAL_STORAGE_UUID = new Property<>("local.storage.uuid", null, String.class);
+
+ /**
+ * Location for KVM virtual router scripts.<br>
+ * The path defined in this property is relative to the directory "/usr/share/cloudstack-common/".<br>
+ * Data type: String.<br>
+ * Default value: <code>scripts/network/domr</code>
+ */
+ public static final Property<String> DOMR_SCRIPTS_DIR = new Property<>("domr.scripts.dir", "scripts/network/domr");
+
+ /**
+ * The timeout (in ms) for time-consuming operations, such as create/copy a snapshot.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>7200</code>
+ */
+ public static final Property<Integer> CMDS_TIMEOUT = new Property<>("cmds.timeout", 7200);
+
+ /**
+ * This parameter sets the VM migration speed (in mbps). The default value is -1,<br>
+ * which means that the agent will try to guess the speed of the guest network and consume all possible bandwidth.<br>
+ * When entering a value, make sure to enter it in megabits per second.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>-1</code>
+ */
+ public static final Property<Integer> VM_MIGRATE_SPEED = new Property<>("vm.migrate.speed", -1);
+
+ /**
+ * Sets target downtime (in ms) at end of livemigration, the 'hiccup' for final copy.<br>
+ * Higher numbers make livemigration easier, lower numbers may cause migration to never complete.<br>
+ * Less than 1 means hypervisor default (20ms).<br>
+ * Data type: Integer.<br>
+ * Default value: <code>-1</code>
+ */
+ public static final Property<Integer> VM_MIGRATE_DOWNTIME = new Property<>("vm.migrate.downtime", -1);
+
+ /**
+ * Busy VMs may never finish migrating, depending on the environment. <br>
+ * Therefore, if configured, this option will pause the VM after the time entered (in ms) to force the migration to finish.<br>
+ * Less than 1 means disabled.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>-1</code>
+ */
+ public static final Property<Integer> VM_MIGRATE_PAUSEAFTER = new Property<>("vm.migrate.pauseafter", -1);
+
+ /**
+ * Time (in seconds) to wait for VM migration to finish. Less than 1 means disabled.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>-1</code>
+ */
+ public static final Property<Integer> VM_MIGRATE_WAIT = new Property<>("vm.migrate.wait", -1);
+
+ /**
+ * Agent Hooks is the way to override default agent behavior to extend the functionality without excessive coding for a custom deployment.<br>
+ * There are 3 arguments needed for the hook to be called: the base directory (defined in agent.hooks.basedir),<br>
+ * the name of the script that is located in the base directory (defined in agent.hooks.*.script)<br>
+ * and the method that is going to be called on the script (defined in agent.hooks.*.method).<br>
+ * This property defines the agent hooks base directory, where all hooks are located.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>/etc/cloudstack/agent/hooks</code>
+ */
+ public static final Property<String> AGENT_HOOKS_BASEDIR = new Property<>("agent.hooks.basedir", "/etc/cloudstack/agent/hooks");
+
+ /**
+ * This property is used with the agent.hooks.basedir property to define the Libvirt VM XML transformer script.<br>
+ * The method to be called on the script is defined in the property agent.hooks.libvirt_vm_xml_transformer.method.<br>
+ * Libvirt XML transformer hook does XML-to-XML transformation.<br>
+ * The provider can use this to add/remove/modify some sort of attributes in Libvirt XML domain specification.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>libvirt-vm-xml-transformer.groovy</code>
+ */
+ public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_SCRIPT = new Property<>("agent.hooks.libvirt_vm_xml_transformer.script", "libvirt-vm-xml-transformer.groovy");
+
+ /**
+ * This property is used with the agent.hooks.basedir and agent.hooks.libvirt_vm_xml_transformer.script properties to define the Libvirt VM XML transformer method.<br>
+ * Libvirt XML transformer hook does XML-to-XML transformation.<br>
+ * The provider can use this to add/remove/modify some sort of attributes in Libvirt XML domain specification.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>transform</code>
+ */
+ public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_METHOD = new Property<>("agent.hooks.libvirt_vm_xml_transformer.method", "transform");
/**
- * Enable manually setting CPU's topology on KVM's VM. <br>
- * Data type: boolean.<br>
- * Default value: true.
+ * This property is used with the agent.hooks.basedir property to define the Libvirt VM on start script.<br>
+ * The method to be called on the script is defined in the property agent.hooks.libvirt_vm_on_start.method.<br>
+ * The hook is called right after Libvirt successfully launched the VM.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>libvirt-vm-state-change.groovy</code>
*/
- public static final Property<Boolean> ENABLE_MANUALLY_SETTING_CPU_TOPOLOGY_ON_KVM_VM = new Property<Boolean>("enable.manually.setting.cpu.topology.on.kvm.vm", true);
+ public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_ON_START_SCRIPT = new Property<>("agent.hooks.libvirt_vm_on_start.script", "libvirt-vm-state-change.groovy");
+
+ /**
+ * This property is used with the agent.hooks.basedir and agent.hooks.libvirt_vm_on_start.script properties to define the Libvirt VM on start method.<br>
+ * The hook is called right after Libvirt successfully launched the VM.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>onStart</code>
+ */
+ public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_ON_START_METHOD = new Property<>("agent.hooks.libvirt_vm_on_start.method", "onStart");
+
+ /**
+ * This property is used with the agent.hooks.basedir property to define the Libvirt VM on stop script.<br>
+ * The method to be called on the script is defined in the property agent.hooks.libvirt_vm_on_stop.method.<br>
+ * The hook is called right after Libvirt successfully stopped the VM.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>libvirt-vm-state-change.groovy</code>
+ */
+ public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_ON_STOP_SCRIPT = new Property<>("agent.hooks.libvirt_vm_on_stop.script", "libvirt-vm-state-change.groovy");
+
+ /**
+ * This property is used with the agent.hooks.basedir and agent.hooks.libvirt_vm_on_stop.script properties to define the Libvirt VM on stop method.<br>
+ * The hook is called right after libvirt successfully stopped the VM.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>onStop</code>
+ */
+ public static final Property<String> AGENT_HOOKS_LIBVIRT_VM_ON_STOP_METHOD = new Property<>("agent.hooks.libvirt_vm_on_stop.method", "onStop");
+
+ /**
+ * Sets the type of bridge used on the hypervisor. This defines what commands the resource will use to setup networking.<br>
+ * Possible values: native | openvswitch <br>
+ * Data type: String.<br>
+ * Default value: <code>native</code>
+ */
+ public static final Property<String> NETWORK_BRIDGE_TYPE = new Property<>("network.bridge.type", "native");
+
+ /**
+ * Sets the driver used to plug and unplug NICs from the bridges.<br>
+ * A sensible default value will be selected based on the network.bridge.type but can be overridden here.<br>
+ * Value for native = com.cloud.hypervisor.kvm.resource.BridgeVifDriver<br>
+ * Value for openvswitch = com.cloud.hypervisor.kvm.resource.OvsVifDriver<br>
+ * Value to enable direct networking in libvirt = com.cloud.hypervisor.kvm.resource.DirectVifDriver (should not be used on hosts that run system VMs)<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> LIBVIRT_VIF_DRIVER = new Property<>("libvirt.vif.driver", null, String.class);
+
+ /**
+ * Setting to enable direct networking in libvirt.<br>
+ * Should not be used on hosts that run system VMs.<br>
+ * For more information see the agent.properties file.<br>
+ * Possible values: private | bridge | vepa <br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> NETWORK_DIRECT_SOURCE_MODE = new Property<>("network.direct.source.mode", null, String.class);
+
+ /**
+ * Setting to enable direct networking in libvirt.<br>
+ * Should not be used on hosts that run system VMs.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> NETWORK_DIRECT_DEVICE = new Property<>("network.direct.device", null, String.class);
+
+ /**
+ * Sets DPDK Support on OpenVSwitch.<br>
+ * Data type: Boolean.<br>
+ * Default value: <code>false</code>
+ */
+ public static final Property<Boolean> OPENVSWITCH_DPDK_ENABLED = new Property<>("openvswitch.dpdk.enabled", false);
+
+ /**
+ * Sets DPDK Support on OpenVSwitch (path).<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> OPENVSWITCH_DPDK_OVS_PATH = new Property<>("openvswitch.dpdk.ovs.path", null, String.class);
+
+ /**
+ * Sets the hypervisor type.<br>
+ * Possible values: kvm | lxc <br>
+ * Data type: String.<br>
+ * Default value: <code>kvm</code>
+ */
+ public static final Property<String> HYPERVISOR_TYPE = new Property<>("hypervisor.type", "kvm");
+
+ /**
+ * Specifies a directory on the host local storage for temporary storing direct download templates.<br>
+ * Data type: String.<br>
+ * Default value: <code>/var/lib/libvirt/images</code>
+ */
+ public static final Property<String> DIRECT_DOWNLOAD_TEMPORARY_DOWNLOAD_LOCATION = new Property<>("direct.download.temporary.download.location",
+ "/var/lib/libvirt/images");
+
+ /**
+ * Specifies a directory on the host local storage for creating and hosting the config drives.<br>
+ * Data type: String.<br>
+ * Default value: <code>/var/cache/cloud</code>
+ */
+ public static final Property<String> HOST_CACHE_LOCATION = new Property<>("host.cache.location", "/var/cache/cloud");
+
+ /**
+ * Sets the rolling maintenance hook scripts directory.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> ROLLING_MAINTENANCE_HOOKS_DIR = new Property<>("rolling.maintenance.hooks.dir", null, String.class);
+
+ /**
+ * Disables the rolling maintenance service execution.<br>
+ * Data type: Boolean.<br>
+ * Default value: <code>false</code>
+ */
+ public static final Property<Boolean> ROLLING_MAINTENANCE_SERVICE_EXECUTOR_DISABLED = new Property<>("rolling.maintenance.service.executor.disabled", false);
+
+ /**
+ * Sets the hypervisor URI.<br>
+ * Value for KVM: qemu:///system<br>
+ * Value for LXC: lxc:///<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> HYPERVISOR_URI = new Property<>("hypervisor.uri", null, String.class);
+
+ /**
+ * Setting to enable the CPU model to KVM guest globally.<br>
+ * Possible values: custom | host-model | host-passthrough <br>
+ * For more information on each value see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> GUEST_CPU_MODE = new Property<>("guest.cpu.mode", null, String.class);
+
+ /**
+ * Custom CPU model. This param is only valid if property guest.cpu.mode=custom.<br>
+ * For more information see the agent.properties file.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> GUEST_CPU_MODEL = new Property<>("guest.cpu.model", null, String.class);
+
+ /**
+ * This param will set the CPU architecture for the domain to override what the management server would send.<br>
+ * In case of arm64 (aarch64), this will change the machine type to 'virt' and add a SCSI and a USB controller in the domain XML.<br>
+ * Possible values: x86_64 | aarch64 <br>
+ * Data type: String.<br>
+ * Default value: <code>null</code> (will set use the architecture of the VM's OS).
+ */
+ public static final Property<String> GUEST_CPU_ARCH = new Property<>("guest.cpu.arch", null, String.class);
+
+ /**
+ * This param will require CPU features on the CPU section.<br>
+ * The features listed in this property must be separated by a blank space (see example below).<br>
+ * Possible values: vmx vme <br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> GUEST_CPU_FEATURES = new Property<>("guest.cpu.features", null, String.class);
/**
* Disables memory ballooning on VM guests for overcommit.<br>
@@ -62,6 +401,319 @@ public class AgentProperties{
*/
public static final Property<Boolean> VM_MEMBALLOON_DISABLE = new Property<>("vm.memballoon.disable", false);
+ /**
+ * Set to true to check disk activity on VM's disks before starting a VM.<br>
+ * This only applies to QCOW2 files, and ensures that there is no other running instance accessing the file before starting.<br>
+ * It works by checking the modified time against the current time, so care must be taken to ensure that the cluster's time is synchronized, otherwise VMs may fail to start.<br>
+ * Data type: Boolean.<br>
+ * Default value: <code>false</code>
+ */
+ public static final Property<Boolean> VM_DISKACTIVITY_CHECKENABLED = new Property<>("vm.diskactivity.checkenabled", false);
+
+ /**
+ * Timeout (in seconds) for giving up on waiting for VM's disk files to become inactive.<br>
+ * Hitting this timeout will result in failure to start VM.<br>
+ * Value must be greater than 0 (zero), otherwise the default value will be used.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>120</code>
+ */
+ public static final Property<Integer> VM_DISKACTIVITY_CHECKTIMEOUT_S = new Property<>("vm.diskactivity.checktimeout_s", 120);
+
+ /**
+ * The length of time (in ms) that the disk needs to be inactive in order to pass the check.<br>
+ * This means current time minus time of disk file needs to be greater than this number.<br>
+ * It also has the side effect of setting the minimum threshold between a stop and start of a given VM.<br>
+ * Value must be greater than 0 (zero), otherwise the default value will be used.<br>
+ * Data type: Long.<br>
+ * Default value: <code>30000L</code>
+ */
+ public static final Property<Long> VM_DISKACTIVITY_INACTIVETIME_MS = new Property<>("vm.diskactivity.inactivetime_ms", 30000L);
+
+ /**
+ * Some newer linux kernels are incapable of reliably migrating VMs with KVMclock.<br>
+ * This is a workaround for the bug, admin can set this to true per-host.<br>
+ * Data type: Boolean.<br>
+ * Default value: <code>false</code>
+ */
+ public static final Property<Boolean> KVMCLOCK_DISABLE = new Property<>("kvmclock.disable", false);
+
+ /**
+ * This enables the VirtIO Random Number Generator device for guests. <br>
+ * Data type: Boolean.<br>
+ * Default value: <code>false</code>
+ */
+ public static final Property<Boolean> VM_RNG_ENABLE = new Property<>("vm.rng.enable", false);
+
+ /**
+ * The model of VirtIO Random Number Generator (RNG) to present to the Guest.<br>
+ * Currently only 'random' is supported.<br>
+ * Data type: String.<br>
+ * Default value: <code>random</code>
+ */
+ public static final Property<String> VM_RNG_MODEL = new Property<>("vm.rng.model", "random");
+
+ /**
+ * Local Random Number Device Generator to use for VirtIO RNG for Guests.<br>
+ * This is usually /dev/random, but it might be different per platform.<br>
+ * Data type: String.<br>
+ * Default value: <code>/dev/random</code>
+ */
+ public static final Property<String> VM_RNG_PATH = new Property<>("vm.rng.path", "/dev/random");
+
+ /**
+ * The amount of bytes the Guest may request/obtain from the RNG in the period specified in the property vm.rng.rate.period.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>2048</code>
+ */
+ public static final Property<Integer> VM_RNG_RATE_BYTES = new Property<>("vm.rng.rate.bytes", 2048);
+
+ /**
+ * The number of milliseconds in which the guest is allowed to obtain the bytes specified in vm.rng.rate.bytes.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>1000</code>
+ */
+ public static final Property<Integer> VM_RNG_RATE_PERIOD = new Property<>("vm.rng.rate.period", 1000);
+
+ /**
+ * Timeout value for aggregation commands to be sent to the virtual router (in seconds).<br>
+ * Data type: Long.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<Long> ROUTER_AGGREGATION_COMMAND_EACH_TIMEOUT = new Property<>("router.aggregation.command.each.timeout", null, Long.class);
+
+ /**
+ * Allows to virtually increase the amount of RAM (in MB) available on the host.<br>
+ * This property can be useful if the host uses Zswap, KSM features and other memory compressing technologies.<br>
+ * For example: if the host has 2GB of RAM and this property is set to 2048, the amount of RAM of the host will be read as 4GB.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>0</code>
+ */
+ public static final Property<Integer> HOST_OVERCOMMIT_MEM_MB = new Property<>("host.overcommit.mem.mb", 0);
+
+ /**
+ * How much host memory (in MB) to reserve for non-allocation.<br>
+ * A useful parameter if a node uses some other software that requires memory, or in case that OOM Killer kicks in.<br>
+ * If this parameter is used, property host.overcommit.mem.mb must be set to 0.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>1024</code>
+ */
+ public static final Property<Integer> HOST_RESERVED_MEM_MB = new Property<>("host.reserved.mem.mb", 1024);
+
+ /**
+ * The model of Watchdog timer to present to the Guest.<br>
+ * For all models refer to the libvirt documentation.<br>
+ * Data type: String.<br>
+ * Default value: <code>i6300esb</code>
+ */
+ public static final Property<String> VM_WATCHDOG_MODEL = new Property<>("vm.watchdog.model", "i6300esb");
+
+ /**
+ * Action to take when the Guest/Instance is no longer notifiying the Watchdog timer.<br>
+ * Possible values: none | reset | poweroff <br>
+ * Data type: String.<br>
+ * Default value: <code>none</code>
+ */
+ public static final Property<String> VM_WATCHDOG_ACTION = new Property<>("vm.watchdog.action", "none");
+
+ /**
+ * Automatically clean up iSCSI sessions not attached to any VM.<br>
+ * Should be enabled for users using managed storage (for example solidfire).<br>
+ * Should be disabled for users with unmanaged iSCSI connections on their hosts.<br>
+ * Data type: Boolean.<br>
+ * Default value: <code>false</code>
+ */
+ public static final Property<Boolean> ISCSI_SESSION_CLEANUP_ENABLED = new Property<>("iscsi.session.cleanup.enabled", false);
+
+ /**
+ * Heartbeat update timeout (in ms).<br>
+ * Depending on the use case, this timeout might need increasing/decreasing.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>60000</code>
+ */
+ public static final Property<Integer> HEARTBEAT_UPDATE_TIMEOUT = new Property<>("heartbeat.update.timeout", 60000);
+
+ /**
+ * The timeout (in seconds) to retrieve the target's domain ID when migrating a VM with KVM. <br>
+ * Data type: Integer. <br>
+ * Default value: <code>10</code>
+ */
+ public static final Property<Integer> VM_MIGRATE_DOMAIN_RETRIEVE_TIMEOUT = new Property<>("vm.migrate.domain.retrieve.timeout", 10);
+
+ /**
+ * This parameter specifies if the host must be rebooted when something goes wrong with the heartbeat.<br>
+ * Data type: Boolean.<br>
+ * Default value: <code>true</code>
+ */
+ public static final Property<Boolean> REBOOT_HOST_AND_ALERT_MANAGEMENT_ON_HEARTBEAT_TIMEOUT
+ = new Property<>("reboot.host.and.alert.management.on.heartbeat.timeout", true);
+
+ /**
+ * Enables manually setting CPU's topology on KVM's VM. <br>
+ * Data type: Boolean.<br>
+ * Default value: <code>true</code>
+ */
+ public static final Property<Boolean> ENABLE_MANUALLY_SETTING_CPU_TOPOLOGY_ON_KVM_VM = new Property<>("enable.manually.setting.cpu.topology.on.kvm.vm", true);
+
+ /**
+ * Manually sets the host CPU speed (in MHz), in cases where CPU scaling support detects the value is wrong. <br>
+ * Data type: Integer.<br>
+ * Default value: <code>0</code>
+ */
+ public static final Property<Integer> HOST_CPU_MANUAL_SPEED_MHZ = new Property<>("host.cpu.manual.speed.mhz", 0);
+
+ /**
+ * Enable manually IO driver on KVM's VM. <br>
+ * Data type: Boolean.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<Boolean> ENABLE_IO_URING = new Property<>("enable.io.uring", null, Boolean.class);
+
+ /**
+ * Defines the location for Hypervisor scripts.<br>
+ * The path defined in this property is relative.<br>
+ * To locate the script, ACS first tries to concatenate the property path with "/usr/share/cloudstack-agent/lib/".<br>
+ * If it fails, it will test each folder of the path, decreasing one by one, until it reaches root.<br>
+ * If the script is not found, ACS will repeat the same steps concatenating the property path with "/usr/share/cloudstack-common/".<br>
+ * The path defined in this property is relative to the directory "/usr/share/cloudstack-common/".<br>
+ * Data type: String.<br>
+ * Default value: <code>scripts/vm/hypervisor</code>
+ */
+ public static final Property<String> HYPERVISOR_SCRIPTS_DIR = new Property<>("hypervisor.scripts.dir", "scripts/vm/hypervisor");
+
+ /**
+ * Defines the location for KVM scripts.<br>
+ * The path defined in this property is relative.<br>
+ * To locate the script, ACS first tries to concatenate the property path with "/usr/share/cloudstack-agent/lib/".<br>
+ * If it fails, it will test each folder of the path, decreasing one by one, until it reaches root.<br>
+ * If the script is not found, ACS will repeat the same steps concatenating the property path with "/usr/share/cloudstack-common/".<br>
+ * The path defined in this property is relative to the directory "/usr/share/cloudstack-common/".<br>
+ * Data type: String.<br>
+ * Default value: <code>scripts/vm/hypervisor/kvm</code>
+ */
+ public static final Property<String> KVM_SCRIPTS_DIR = new Property<>("kvm.scripts.dir", "scripts/vm/hypervisor/kvm");
+
+ /**
+ * Specifies start MAC address for private IP range.<br>
+ * Data type: String.<br>
+ * Default value: <code>00:16:3e:77:e2:a0</code>
+ */
+ public static final Property<String> PRIVATE_MACADDR_START = new Property<>("private.macaddr.start", "00:16:3e:77:e2:a0");
+
+ /**
+ * Specifies start IP for private IP range. <br>
+ * Data type: String.<br>
+ * Default value: <code>192.168.166.128</code>
+ */
+ public static final Property<String> PRIVATE_IPADDR_START = new Property<>("private.ipaddr.start", "192.168.166.128");
+
+ /**
+ * Defines Local Bridge Name.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> PRIVATE_BRIDGE_NAME = new Property<>("private.bridge.name", null, String.class);
+
+ /**
+ * Defines private network name.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> PRIVATE_NETWORK_NAME = new Property<>("private.network.name", null, String.class);
+
+ /**
+ * Defines the location for network scripts.<br>
+ * The path defined in this property is relative.<br>
+ * To locate the script, ACS first tries to concatenate the property path with "/usr/share/cloudstack-agent/lib/".<br>
+ * If it fails, it will test each folder of the path, decreasing one by one, until it reaches root.<br>
+ * If the script is not found, ACS will repeat the same steps concatenating the property path with "/usr/share/cloudstack-common/".<br>
+ * The path defined in this property is relative to the directory "/usr/share/cloudstack-common/".<br>
+ * Data type: String.<br>
+ * Default value: <code>scripts/vm/network/vnet</code>
+ */
+ public static final Property<String> NETWORK_SCRIPTS_DIR = new Property<>("network.scripts.dir", "scripts/vm/network/vnet");
+
+ /**
+ * Defines the location for storage scripts.<br>
+ * The path defined in this property is relative.<br>
+ * To locate the script, ACS first tries to concatenate the property path with "/usr/share/cloudstack-agent/lib/".<br>
+ * If it fails, it will test each folder of the path, decreasing one by one, until it reaches root.<br>
+ * If the script is not found, ACS will repeat the same steps concatenating the property path with "/usr/share/cloudstack-common/".<br>
+ * The path defined in this property is relative to the directory "/usr/share/cloudstack-common/".<br>
+ * Data type: String.<br>
+ * Default value: <code>scripts/storage/qcow2</code>
+ */
+ public static final Property<String> STORAGE_SCRIPTS_DIR = new Property<>("storage.scripts.dir", "scripts/storage/qcow2");
+
+ /**
+ * Time (in seconds) to wait for the VM to shutdown gracefully.<br>
+ * If the time is exceeded shutdown will be forced.<br>
+ * Data type: Integer.<br>
+ * Default value: <code>120</code>
+ */
+ public static final Property<Integer> STOP_SCRIPT_TIMEOUT = new Property<>("stop.script.timeout", 120);
+
+ /**
+ * Definition of VMs video model type.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> VM_VIDEO_HARDWARE = new Property<>("vm.video.hardware", null, String.class);
+
+ /**
+ * Definition of VMs video, specifies the amount of RAM in kibibytes (blocks of 1024 bytes).<br>
+ * Data type: Integer.<br>
+ * Default value: <code>0</code>
+ */
+ public static final Property<Integer> VM_VIDEO_RAM = new Property<>("vm.video.ram", 0);
+
+ /**
+ * System VM ISO path.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> SYSTEMVM_ISO_PATH = new Property<>("systemvm.iso.path", null, String.class);
+
+ /**
+ * If set to "true", allows override of the properties: private.macaddr.start, private.ipaddr.start, private.ipaddr.end.<br>
+ * Data type: Boolean.<br>
+ * Default value: <code>false</code>
+ */
+ public static final Property<Boolean> DEVELOPER = new Property<>("developer", false);
+
+ /**
+ * Can only be used if developer = true. This property is used to define the local bridge name and private network name.<br>
+ * Data type: String.<br>
+ * Default value: <code>null</code>
+ */
+ public static final Property<String> INSTANCE = new Property<>("instance", null, String.class);
+
+ /**
+ * Shows the path to the base directory in which NFS servers are going to be mounted.<br>
+ * Data type: String.<br>
+ * Default value: <code>/mnt</code>
+ */
+ public static final Property<String> MOUNT_PATH = new Property<>("mount.path", "/mnt");
+
+ /**
+ * Port listened by the console proxy.
+ * Data type: Integer.<br>
+ * Default value: <code>443</code>
+ */
+ public static final Property<Integer> CONSOLEPROXY_HTTPLISTENPORT = new Property<>("consoleproxy.httpListenPort", 443);
+
+ /**
+ * Data type: Integer.<br>
+ * Default value: <code>5</code>
+ */
+ public static final Property<Integer> PING_RETRIES = new Property<>("ping.retries", 5);
+
+ /**
+ * Returns {@link AgentProperties#workers}.
+ */
+ public Property<Integer> getWorkers() {
+ return workers;
+ }
+
/**
* The time interval (in seconds) at which the balloon driver will get memory stats updates. This is equivalent to Libvirt's <code>--period</code> parameter when using the dommemstat command.
* Data type: Integer.<br>
@@ -70,12 +722,26 @@ public class AgentProperties{
public static final Property<Integer> VM_MEMBALLOON_STATS_PERIOD = new Property<>("vm.memballoon.stats.period", 0);
public static class Property <T>{
- private final String name;
- private final T defaultValue;
+ private String name;
+ private T defaultValue;
+ private Class<T> typeClass;
+
+ Property(String name, T value) {
+ init(name, value);
+ }
+
+ Property(String name, T defaultValue, Class<T> typeClass) {
+ this.typeClass = typeClass;
+ init(name, defaultValue);
+ }
- private Property(String name, T value) {
+ private void init(String name, T defaultValue) {
this.name = name;
- this.defaultValue = value;
+ this.defaultValue = defaultValue;
+
+ if (defaultValue != null) {
+ this.typeClass = (Class<T>)defaultValue.getClass();
+ }
}
public String getName() {
@@ -85,5 +751,9 @@ public class AgentProperties{
public T getDefaultValue() {
return defaultValue;
}
+
+ public Class<T> getTypeClass() {
+ return typeClass;
+ }
}
}
diff --git a/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java b/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java
index 6d515f0004f..602aa1efcb0 100644
--- a/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java
+++ b/agent/src/main/java/com/cloud/agent/properties/AgentPropertiesFileHandler.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import org.apache.cloudstack.utils.security.KeyStoreUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.IntegerConverter;
+import org.apache.commons.beanutils.converters.LongConverter;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
@@ -45,23 +46,32 @@ public class AgentPropertiesFileHandler {
File agentPropertiesFile = PropertiesUtil.findConfigFile(KeyStoreUtils.AGENT_PROPSFILE);
- if (agentPropertiesFile != null) {
- try {
- String configValue = PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(name);
- if (StringUtils.isNotBlank(configValue)) {
- if (defaultValue instanceof Integer) {
- ConvertUtils.register(new IntegerConverter(defaultValue), Integer.class);
- }
+ if (agentPropertiesFile == null) {
+ logger.debug(String.format("File [%s] was not found, we will use default defined values. Property [%s]: [%s].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue));
+
+ return defaultValue;
+ }
- return (T)ConvertUtils.convert(configValue, defaultValue.getClass());
- } else {
- logger.debug(String.format("Property [%s] has empty or null value. Using default value [%s].", name, defaultValue));
- }
- } catch (IOException ex) {
- logger.debug(String.format("Failed to get property [%s]. Using default value [%s].", name, defaultValue), ex);
+ try {
+ String configValue = PropertiesUtil.loadFromFile(agentPropertiesFile).getProperty(name);
+ if (StringUtils.isBlank(configValue)) {
+ logger.debug(String.format("Property [%s] has empty or null value. Using default value [%s].", name, defaultValue));
+ return defaultValue;
}
- } else {
- logger.debug(String.format("File [%s] was not found, we will use default defined values. Property [%s]: [%s].", KeyStoreUtils.AGENT_PROPSFILE, name, defaultValue));
+
+ if (defaultValue instanceof Integer) {
+ ConvertUtils.register(new IntegerConverter(defaultValue), Integer.class);
+ }
+
+ if (defaultValue instanceof Long) {
+ ConvertUtils.register(new LongConverter(defaultValue), Long.class);
+ }
+
+ logger.debug(String.format("Property [%s] was altered. Now using the value [%s].", name, configValue));
+ return (T)ConvertUtils.convert(configValue, property.getTypeClass());
+
+ } catch (IOException ex) {
+ logger.debug(String.format("Failed to get property [%s]. Using default value [%s].", name, defaultValue), ex);
}
return defaultValue;
diff --git a/agent/src/test/java/com/cloud/agent/AgentShellTest.java b/agent/src/test/java/com/cloud/agent/AgentShellTest.java
index 868293c8977..27bc3dcbde3 100644
--- a/agent/src/test/java/com/cloud/agent/AgentShellTest.java
+++ b/agent/src/test/java/com/cloud/agent/AgentShellTest.java
@@ -17,17 +17,47 @@
package com.cloud.agent;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
import javax.naming.ConfigurationException;
+import com.cloud.agent.properties.AgentProperties;
+import com.cloud.agent.properties.AgentPropertiesFileHandler;
import org.junit.Assert;
import org.junit.Test;
import com.cloud.utils.StringUtils;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.Spy;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+@RunWith(PowerMockRunner.class)
public class AgentShellTest {
+
+ @InjectMocks
+ @Spy
+ AgentShell agentShellSpy = new AgentShell();
+
+ @Mock
+ AgentProperties agentPropertiesMock;
+
+ @Mock
+ AgentProperties.Property<Integer> propertyIntegerMock;
+
+ @Mock
+ AgentProperties.Property<String> propertyStringMock;
+
+ @Mock
+ UUID uuidMock;
+
@Test
public void parseCommand() throws ConfigurationException {
AgentShell shell = new AgentShell();
@@ -59,4 +89,282 @@ public class AgentShellTest {
}
Assert.assertEquals(shell.getNextHost(), hosts.get(0));
}
+
+ @Test
+ public void isValueStartingAndEndingWithAtSignTestValues() {
+ Map<String, Boolean> valuesAndExpects = new HashMap<>();
+ valuesAndExpects.put("@test@", true);
+ valuesAndExpects.put("test@", false);
+ valuesAndExpects.put("@test", false);
+ valuesAndExpects.put("test", false);
+ valuesAndExpects.put("te@st", false);
+
+ valuesAndExpects.forEach((value, expected) -> {
+ boolean result = agentShellSpy.isValueStartingAndEndingWithAtSign(value);
+ Assert.assertEquals(String.format("Test with value [%s] does not return as expected.", value), expected, result);
+ });
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getPortOrWorkersTestValueIsNullGetFromProperty() {
+ int expected = 195;
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
+
+ int result = agentShellSpy.getPortOrWorkers(null, propertyIntegerMock);
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getPortOrWorkersTestValueIsNotAValidIntegerReturnDefaultFromProperty() {
+ int expected = 42;
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ Mockito.doReturn(expected).when(propertyIntegerMock).getDefaultValue();
+
+ int result = agentShellSpy.getPortOrWorkers("test", propertyIntegerMock);
+ Assert.assertEquals(expected, result);
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
+ AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getPortOrWorkersTestValueIsAValidIntegerReturnValue() {
+ int expected = 42;
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ Mockito.doReturn(79).when(propertyIntegerMock).getDefaultValue();
+
+ int result = agentShellSpy.getPortOrWorkers(String.valueOf(expected), propertyIntegerMock);
+ Assert.assertEquals(expected, result);
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
+ AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
+ }
+
+ @Test
+ public void getWorkersTestWorkersLessThan0ReturnDefault() {
+ int expected = 42;
+
+ Mockito.doReturn(propertyIntegerMock).when(agentPropertiesMock).getWorkers();
+ Mockito.doReturn(-1).when(agentShellSpy).getPortOrWorkers(Mockito.any(), Mockito.any());
+ Mockito.doReturn(expected).when(propertyIntegerMock).getDefaultValue();
+
+ int result = agentShellSpy.getWorkers("");
+
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test
+ public void getWorkersTestWorkersEqualTo0ReturnDefault() {
+ int expected = 42;
+
+ Mockito.doReturn(propertyIntegerMock).when(agentPropertiesMock).getWorkers();
+ Mockito.doReturn(0).when(agentShellSpy).getPortOrWorkers(Mockito.any(), Mockito.any());
+ Mockito.doReturn(expected).when(propertyIntegerMock).getDefaultValue();
+
+ int result = agentShellSpy.getWorkers("");
+
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test
+ public void getWorkersTestWorkersHigherThan0ReturnValue() {
+ int expected = 1;
+ Mockito.doReturn(expected).when(agentShellSpy).getPortOrWorkers(Mockito.any(), Mockito.any());
+
+ int result = agentShellSpy.getWorkers("");
+
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getZoneOrPodTestValueIsNullAndPropertyStartsAndEndsWithAtSignReturnPropertyDefaultValue() {
+ String expected = "default";
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn("test");
+
+ Mockito.doReturn(true).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
+ Mockito.doReturn(expected).when(propertyStringMock).getDefaultValue();
+
+ String result = agentShellSpy.getZoneOrPod(null, propertyStringMock);
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getZoneOrPodTestValueIsNullAndPropertyDoesNotStartAndEndWithAtSignReturnPropertyDefaultValue() {
+ String expected = "test";
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
+
+ Mockito.doReturn(false).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
+ Mockito.doReturn("default").when(propertyStringMock).getDefaultValue();
+
+ String result = agentShellSpy.getZoneOrPod(null, propertyStringMock);
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getZoneOrPodTestValueIsNotNullAndStartsAndEndsWithAtSignReturnPropertyDefaultValue() {
+ String expected = "default";
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+
+ Mockito.doReturn(true).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
+ Mockito.doReturn(expected).when(propertyStringMock).getDefaultValue();
+
+ String result = agentShellSpy.getZoneOrPod("test", propertyStringMock);
+ Assert.assertEquals(expected, result);
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
+ AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getZoneOrPodTestValueIsNotNullAndDoesNotStartAndEndWithAtSignReturnPropertyDefaultValue() {
+ String expected = "test";
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+
+ Mockito.doReturn(false).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
+ Mockito.doReturn("default").when(propertyStringMock).getDefaultValue();
+
+ String result = agentShellSpy.getZoneOrPod(expected, propertyStringMock);
+ Assert.assertEquals(expected, result);
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
+ AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
+ }
+
+ @Test
+ public void getGuidTestGuidNotNullReturnIt() throws ConfigurationException {
+ String expected = "test";
+ String result = agentShellSpy.getGuid(expected);
+
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getGuidTestGuidIsNullReturnProperty() throws ConfigurationException {
+ String expected = "test";
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
+
+ String result = agentShellSpy.getGuid(null);
+
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test
+ @PrepareForTest({AgentShell.class, AgentPropertiesFileHandler.class})
+ public void getGuidTestGuidAndPropertyAreNullIsDeveloperGenerateNewUuid() throws ConfigurationException {
+ String expected = "test";
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class, UUID.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(null, true);
+ PowerMockito.when(UUID.randomUUID()).thenReturn(uuidMock);
+ Mockito.doReturn(expected).when(uuidMock).toString();
+
+ String result = agentShellSpy.getGuid(null);
+
+ Assert.assertEquals(expected, result);
+ }
+
+ @Test(expected = ConfigurationException.class)
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void getGuidTestGuidAndPropertyAreNullIsNotDeveloperThrowConfigurationException() throws ConfigurationException {
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(null, false);
+
+ agentShellSpy.getGuid(null);
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void setHostTestValueIsNotNullAndStartsAndEndsWithAtSignThrowConfigurationException(){
+ Mockito.doReturn(true).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+
+ boolean error = false;
+
+ try {
+ agentShellSpy.setHost("test");
+ } catch (ConfigurationException e) {
+ error = true;
+ }
+
+ if (!error) {
+ throw new AssertionError("This test expects a ConfigurationException.");
+ }
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
+ AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void setHostTestValueIsNullPropertyStartsAndEndsWithAtSignThrowConfigurationException(){
+ Mockito.doReturn(true).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn("test");
+
+ boolean error = false;
+
+ try {
+ agentShellSpy.setHost(null);
+ } catch (ConfigurationException e) {
+ error = true;
+ }
+
+ if (!error) {
+ throw new AssertionError("This test expects a ConfigurationException.");
+ }
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class);
+ AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void setHostTestValueIsNotNullAndDoesNotStartAndEndWithAtSignSetHosts() throws ConfigurationException {
+ String expected = "test";
+ Mockito.doReturn(false).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+
+ agentShellSpy.setHost(expected);
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.never());
+ AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
+
+ Mockito.verify(agentShellSpy).setHosts(expected);
+ }
+
+ @Test
+ @PrepareForTest(AgentPropertiesFileHandler.class)
+ public void setHostTestValueIsNullPropertyDoesNotStartAndEndWithAtSignSetHosts() throws ConfigurationException {
+ String expected = "test";
+
+ Mockito.doReturn(false).when(agentShellSpy).isValueStartingAndEndingWithAtSign(Mockito.any());
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn(expected);
+
+ agentShellSpy.setHost(null);
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class);
+ AgentPropertiesFileHandler.getPropertyValue(Mockito.any());
+
+ Mockito.verify(agentShellSpy).setHosts(expected);
+ }
}
diff --git a/agent/src/test/java/com/cloud/agent/properties/AgentPropertiesFileHandlerTest.java b/agent/src/test/java/com/cloud/agent/properties/AgentPropertiesFileHandlerTest.java
index d91d0e03fb2..1a73bf24256 100644
--- a/agent/src/test/java/com/cloud/agent/properties/AgentPropertiesFileHandlerTest.java
+++ b/agent/src/test/java/com/cloud/agent/properties/AgentPropertiesFileHandlerTest.java
@@ -44,12 +44,29 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
@Mock
AgentProperties.Property<Integer> agentPropertiesIntegerMock;
+ @Mock
+ AgentProperties.Property<Long> agentPropertiesLongMock;
+
@Mock
File fileMock;
@Mock
Properties propertiesMock;
+ @Test
+ public void getPropertyValueTestFileNotFoundReturnDefaultValueNull() throws Exception{
+ String expectedResult = null;
+
+ AgentProperties.Property<String> agentPropertiesStringMock = new AgentProperties.Property<String>("Test-null", null, String.class);
+
+ PowerMockito.mockStatic(PropertiesUtil.class);
+ PowerMockito.doReturn(null).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
+
+ String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
+
+ Assert.assertEquals(expectedResult, result);
+ }
+
@Test
public void validateGetPropertyValueFileNotFoundReturnDefaultValue() throws Exception{
String expectedResult = "default value";
@@ -125,11 +142,28 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
Assert.assertEquals(expectedResult, result);
}
+ @Test
+ public void getPropertyValueTestValidPropertyReturnPropertyValueWhenDefaultValueIsNull() throws Exception {
+ String expectedResult = "test";
+
+ AgentProperties.Property<String> agentPropertiesStringMock = new AgentProperties.Property<String>("Test-null", null, String.class);
+
+ PowerMockito.mockStatic(PropertiesUtil.class);
+ PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
+ PowerMockito.doReturn(propertiesMock).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
+ Mockito.doReturn(expectedResult).when(propertiesMock).getProperty(Mockito.anyString());
+
+ String result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesStringMock);
+
+ Assert.assertEquals(expectedResult, result);
+ }
+
@Test
public void validateGetPropertyValueValidIntegerPropertyReturnPropertyValue() throws Exception{
Integer expectedResult = 2;
Mockito.doReturn(1).when(agentPropertiesIntegerMock).getDefaultValue();
Mockito.doReturn("name").when(agentPropertiesIntegerMock).getName();
+ Mockito.doReturn(Integer.class).when(agentPropertiesIntegerMock).getTypeClass();
PowerMockito.mockStatic(PropertiesUtil.class);
PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
@@ -140,4 +174,22 @@ public class AgentPropertiesFileHandlerTest extends TestCase {
Assert.assertEquals(expectedResult, result);
}
+
+ @Test
+ public void getPropertyValueTestValidLongPropertyReturnPropertyValue() throws Exception{
+ Long expectedResult = 600L;
+ Mockito.doReturn(1L).when(agentPropertiesLongMock).getDefaultValue();
+ Mockito.doReturn("name").when(agentPropertiesLongMock).getName();
+ Mockito.doReturn(Long.class).when(agentPropertiesLongMock).getTypeClass();
+
+ PowerMockito.mockStatic(PropertiesUtil.class);
+ PowerMockito.doReturn(fileMock).when(PropertiesUtil.class, "findConfigFile", Mockito.anyString());
+ PowerMockito.doReturn(propertiesMock).when(PropertiesUtil.class, "loadFromFile", Mockito.any());
+ Mockito.doReturn(String.valueOf(expectedResult)).when(propertiesMock).getProperty(Mockito.anyString());
+
+ Long result = AgentPropertiesFileHandler.getPropertyValue(agentPropertiesLongMock);
+
+ Assert.assertEquals(expectedResult, result);
+ }
+
}
diff --git a/agent/src/test/java/com/cloud/agent/properties/AgentPropertiesTest.java b/agent/src/test/java/com/cloud/agent/properties/AgentPropertiesTest.java
new file mode 100644
index 00000000000..9f40feef96e
--- /dev/null
+++ b/agent/src/test/java/com/cloud/agent/properties/AgentPropertiesTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.cloud.agent.properties;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.lang.reflect.Field;
+
+public class AgentPropertiesTest {
+
+ @Test
+ public void initTestBlockInstanceWithNullValueAndWithoutType() throws IllegalAccessException {
+ AgentProperties agentProperties = new AgentProperties();
+ Field[] fields = agentProperties.getClass().getDeclaredFields();
+
+ for (Field field : fields) {
+ if (field.getType().equals(AgentProperties.Property.class)) {
+ AgentProperties.Property property = (AgentProperties.Property) field.get(agentProperties);
+
+ Assert.assertTrue(String.format("Either inform the default value or the class of property [%s], field [%s].", property.getName(), field.getName()),
+ property.getDefaultValue() != null || property.getTypeClass() != null);
+ }
+ }
+ }
+}
diff --git a/core/src/main/java/com/cloud/resource/ServerResourceBase.java b/core/src/main/java/com/cloud/resource/ServerResourceBase.java
index f68bcf409ef..f3bad610998 100644
--- a/core/src/main/java/com/cloud/resource/ServerResourceBase.java
+++ b/core/src/main/java/com/cloud/resource/ServerResourceBase.java
@@ -24,14 +24,17 @@ import java.io.StringWriter;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
import java.util.Date;
-import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.naming.ConfigurationException;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import com.cloud.agent.IAgentControl;
@@ -67,60 +70,12 @@ public abstract class ServerResourceBase implements ServerResource {
public boolean configure(final String name, Map<String, Object> params) throws ConfigurationException {
_name = name;
- String publicNic = (String)params.get("public.network.device");
- if (publicNic == null) {
- publicNic = "xenbr1";
- }
- String privateNic = (String)params.get("private.network.device");
- if (privateNic == null) {
- privateNic = "xenbr0";
- }
- final String storageNic = (String)params.get("storage.network.device");
- final String storageNic2 = (String)params.get("storage.network.device.2");
-
- _privateNic = getNetworkInterface(privateNic);
- _publicNic = getNetworkInterface(publicNic);
- _storageNic = getNetworkInterface(storageNic);
- _storageNic2 = getNetworkInterface(storageNic2);
+ defineResourceNetworkInterfaces(params);
if (_privateNic == null) {
- s_logger.warn("Nics are not specified in properties file/db, will try to autodiscover");
-
- Enumeration<NetworkInterface> nics = null;
- try {
- nics = NetworkInterface.getNetworkInterfaces();
- if (nics == null || !nics.hasMoreElements()) {
- throw new ConfigurationException("Private NIC is not configured");
- }
- } catch (final SocketException e) {
- throw new ConfigurationException("Private NIC is not configured");
- }
-
- while (nics.hasMoreElements()) {
- final NetworkInterface nic = nics.nextElement();
- final String nicName = nic.getName();
- // try {
- if (//!nic.isLoopback() &&
- //nic.isUp() &&
- !nic.isVirtual() && !nicName.startsWith("vnif") && !nicName.startsWith("vnbr") && !nicName.startsWith("peth") && !nicName.startsWith("vif") &&
- !nicName.startsWith("virbr") && !nicName.contains(":")) {
- final String[] info = NetUtils.getNicParams(nicName);
- if (info != null && info[0] != null) {
- _privateNic = nic;
- s_logger.info("Designating private to be nic " + nicName);
- break;
- }
- }
- // } catch (final SocketException e) {
- // s_logger.warn("Error looking at " + nicName, e);
- // }
- s_logger.debug("Skipping nic " + nicName);
- }
-
- if (_privateNic == null) {
- throw new ConfigurationException("Private NIC is not configured");
- }
+ tryToAutoDiscoverResourcePrivateNetworkInterface();
}
+
String infos[] = NetUtils.getNetworkParams(_privateNic);
if (infos == null) {
s_logger.warn("Incorrect details for private Nic during initialization of ServerResourceBase");
@@ -132,31 +87,67 @@ public abstract class ServerResourceBase implements ServerResource {
return true;
}
- protected NetworkInterface getNetworkInterface(String nicName) {
- s_logger.debug("Retrieving network interface: " + nicName);
- if (nicName == null) {
- return null;
- }
+ protected void defineResourceNetworkInterfaces(Map<String, Object> params) {
+ String privateNic = (String) params.get("private.network.device");
+ privateNic = privateNic == null ? "xenbr0" : privateNic;
- if (nicName.trim().length() == 0) {
- return null;
- }
+ String publicNic = (String) params.get("public.network.device");
+ publicNic = publicNic == null ? "xenbr1" : publicNic;
+
+ String storageNic = (String) params.get("storage.network.device");
+ String storageNic2 = (String) params.get("storage.network.device.2");
+
+ _privateNic = NetUtils.getNetworkInterface(privateNic);
+ _publicNic = NetUtils.getNetworkInterface(publicNic);
+ _storageNic = NetUtils.getNetworkInterface(storageNic);
+ _storageNic2 = NetUtils.getNetworkInterface(storageNic2);
+ }
- nicName = nicName.trim();
+ protected void tryToAutoDiscoverResourcePrivateNetworkInterface() throws ConfigurationException {
+ s_logger.info("Trying to autodiscover this resource's private network interface.");
- NetworkInterface nic;
+ List<NetworkInterface> nics;
try {
- nic = NetworkInterface.getByName(nicName);
- if (nic == null) {
- s_logger.debug("Unable to get network interface for " + nicName);
- return null;
+ nics = Collections.list(NetworkInterface.getNetworkInterfaces());
+ if (CollectionUtils.isEmpty(nics)) {
+ throw new ConfigurationException("This resource has no NICs. Unable to configure it.");
+ }
+ } catch (SocketException e) {
+ throw new ConfigurationException(String.format("Could not retrieve the environment NICs due to [%s].", e.getMessage()));
+ }
+
+ s_logger.debug(String.format("Searching the private NIC along the environment NICs [%s].", Arrays.toString(nics.toArray())));
+
+ for (NetworkInterface nic : nics) {
+ if (isValidNicToUseAsPrivateNic(nic)) {
+ s_logger.info(String.format("Using NIC [%s] as private NIC.", nic));
+ _privateNic = nic;
+ return;
}
+ }
+
+ throw new ConfigurationException("It was not possible to define a private NIC for this resource.");
+ }
- return nic;
- } catch (final SocketException e) {
- s_logger.warn("Unable to get network interface for " + nicName, e);
- return null;
+ protected boolean isValidNicToUseAsPrivateNic(NetworkInterface nic) {
+ String nicName = nic.getName();
+
+ s_logger.debug(String.format("Verifying if NIC [%s] can be used as private NIC.", nic));
+
+ String[] nicNameStartsToAvoid = {"vnif", "vnbr", "peth", "vif", "virbr"};
+ if (nic.isVirtual() || StringUtils.startsWithAny(nicName, nicNameStartsToAvoid) || nicName.contains(":")) {
+ s_logger.debug(String.format("Not using NIC [%s] because it is either virtual, starts with %s, or contains \":\"" +
+ " in its name.", Arrays.toString(nicNameStartsToAvoid), nic));
+ return false;
+ }
+
+ String[] info = NetUtils.getNicParams(nicName);
+ if (info == null || info[0] == null) {
+ s_logger.debug(String.format("Not using NIC [%s] because it does not have a valid IP to use as the private IP.", nic));
+ return false;
}
+
+ return true;
}
protected void fillNetworkInformation(final StartupCommand cmd) {
diff --git a/core/src/test/java/com/cloud/resource/ServerResourceBaseTest.java b/core/src/test/java/com/cloud/resource/ServerResourceBaseTest.java
new file mode 100644
index 00000000000..d9df73fb9b1
--- /dev/null
+++ b/core/src/test/java/com/cloud/resource/ServerResourceBaseTest.java
@@ -0,0 +1,241 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.resource;
+
+import com.cloud.utils.net.NetUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import javax.naming.ConfigurationException;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+@RunWith(PowerMockRunner.class)
+public class ServerResourceBaseTest {
+
+ private static final String[] NIC_NAME_STARTS_TO_AVOID = {"vnif", "vnbr", "peth", "vif", "virbr"};
+
+ ServerResourceBase serverResourceBaseSpy = Mockito.spy(ServerResourceBase.class);
+
+ NetworkInterface networkInterfaceMock1, networkInterfaceMock2, networkInterfaceMock3, networkInterfaceMock4;
+
+ @Captor
+ ArgumentCaptor<String> keyCaptor;
+
+ @Before
+ public void setup() {
+ networkInterfaceMock1 = PowerMockito.mock(NetworkInterface.class);
+ networkInterfaceMock2 = PowerMockito.mock(NetworkInterface.class);
+ networkInterfaceMock3 = PowerMockito.mock(NetworkInterface.class);
+ networkInterfaceMock4 = PowerMockito.mock(NetworkInterface.class);
+ }
+
+ @Test
+ @PrepareForTest(ServerResourceBase.class)
+ public void isValidNicToUseAsPrivateNicTestReturnFalseWhenNicIsVirtual() {
+ NetworkInterface networkInterfaceMock = PowerMockito.mock(NetworkInterface.class);
+ PowerMockito.when(networkInterfaceMock.isVirtual()).thenReturn(true);
+
+ Assert.assertFalse(serverResourceBaseSpy.isValidNicToUseAsPrivateNic(networkInterfaceMock));
+ }
+
+ @Test
+ @PrepareForTest(ServerResourceBase.class)
+ public void isValidNicToUseAsPrivateNicTestReturnFalseWhenNicNameStartsWithOneOfTheAvoidList() {
+ NetworkInterface networkInterfaceMock = PowerMockito.mock(NetworkInterface.class);
+ PowerMockito.when(networkInterfaceMock.isVirtual()).thenReturn(false);
+ PowerMockito.when(networkInterfaceMock.getName()).thenReturn("vniftest", "vnbrtest", "pethtest", "viftest", "virbrtest");
+
+ Arrays.asList(NIC_NAME_STARTS_TO_AVOID).forEach(type -> Assert.assertFalse(serverResourceBaseSpy.isValidNicToUseAsPrivateNic(networkInterfaceMock)));
+ }
+
+ @Test
+ @PrepareForTest(ServerResourceBase.class)
+ public void isValidNicToUseAsPrivateNicTestReturnFalseWhenNicNameContainsColon() {
+ NetworkInterface networkInterfaceMock = PowerMockito.mock(NetworkInterface.class);
+ PowerMockito.when(networkInterfaceMock.isVirtual()).thenReturn(false);
+ PowerMockito.when(networkInterfaceMock.getName()).thenReturn("te:st");
+
+ Assert.assertFalse(serverResourceBaseSpy.isValidNicToUseAsPrivateNic(networkInterfaceMock));
+ }
+
+ @Test
+ @PrepareForTest({ServerResourceBase.class, NetUtils.class})
+ public void isValidNicToUseAsPrivateNicTestReturnFalseWhenNetUtilsGetNicParamsReturnsNull() {
+ NetworkInterface networkInterfaceMock = PowerMockito.mock(NetworkInterface.class);
+ PowerMockito.when(networkInterfaceMock.isVirtual()).thenReturn(false);
+ PowerMockito.when(networkInterfaceMock.getName()).thenReturn("testvnif", "testvnbr", "testpeth", "testvif", "testvirbr");
+
+ PowerMockito.mockStatic(NetUtils.class);
+ PowerMockito.when(NetUtils.getNicParams(Mockito.anyString())).thenReturn(null);
+
+ Arrays.asList(NIC_NAME_STARTS_TO_AVOID).forEach(type -> {
+ Assert.assertFalse(serverResourceBaseSpy.isValidNicToUseAsPrivateNic(networkInterfaceMock));
+ });
+ }
+
+ @Test
+ @PrepareForTest({ServerResourceBase.class, NetUtils.class})
+ public void isValidNicToUseAsPrivateNicTestReturnFalseWhenNetUtilsGetNicParamsReturnsFirstElementNull() {
+ NetworkInterface networkInterfaceMock = PowerMockito.mock(NetworkInterface.class);
+ PowerMockito.when(networkInterfaceMock.isVirtual()).thenReturn(false);
+ PowerMockito.when(networkInterfaceMock.getName()).thenReturn("testvnif", "testvnbr", "testpeth", "testvif", "testvirbr");
+
+ PowerMockito.mockStatic(NetUtils.class);
+ PowerMockito.when(NetUtils.getNicParams(Mockito.anyString())).thenReturn(new String[]{null});
+
+ Arrays.asList(NIC_NAME_STARTS_TO_AVOID).forEach(type -> {
+ Assert.assertFalse(serverResourceBaseSpy.isValidNicToUseAsPrivateNic(networkInterfaceMock));
+ });
+ }
+
+ @Test
+ @PrepareForTest({ServerResourceBase.class, NetUtils.class})
+ public void isValidNicToUseAsPrivateNicTestReturnTrueWhenNetUtilsGetNicParamsReturnsAValidFirstElement() {
+ NetworkInterface networkInterfaceMock = PowerMockito.mock(NetworkInterface.class);
+ PowerMockito.when(networkInterfaceMock.isVirtual()).thenReturn(false);
+ PowerMockito.when(networkInterfaceMock.getName()).thenReturn("testvnif", "testvnbr", "testpeth", "testvif", "testvirbr");
+
+ PowerMockito.mockStatic(NetUtils.class);
+ PowerMockito.when(NetUtils.getNicParams(Mockito.anyString())).thenReturn(new String[]{"test"});
+
+ Arrays.asList(NIC_NAME_STARTS_TO_AVOID).forEach(type -> {
+ Assert.assertTrue(serverResourceBaseSpy.isValidNicToUseAsPrivateNic(networkInterfaceMock));
+ });
+ }
+
+ @Test(expected = ConfigurationException.class)
+ @PrepareForTest(ServerResourceBase.class)
+ public void tryToAutoDiscoverResourcePrivateNetworkInterfaceTestThrowConfigurationExceptionWhenNicsDoesNotHaveMoreElements() throws SocketException, ConfigurationException {
+ PowerMockito.mockStatic(NetworkInterface.class);
+ PowerMockito.when(NetworkInterface.getNetworkInterfaces()).thenReturn(Collections.enumeration(new ArrayList<>()));
+
+ serverResourceBaseSpy.tryToAutoDiscoverResourcePrivateNetworkInterface();
+ }
+
+ @Test(expected = ConfigurationException.class)
+ @PrepareForTest(ServerResourceBase.class)
+ public void tryToAutoDiscoverResourcePrivateNetworkInterfaceTestThrowConfigurationExceptionWhenNicsGetNetworkInterfacesThrowsSocketException() throws SocketException, ConfigurationException {
+ PowerMockito.mockStatic(NetworkInterface.class);
+ PowerMockito.when(NetworkInterface.getNetworkInterfaces()).thenThrow(SocketException.class);
+
+ serverResourceBaseSpy.tryToAutoDiscoverResourcePrivateNetworkInterface();
+ }
+
+ @Test(expected = ConfigurationException.class)
+ @PrepareForTest(ServerResourceBase.class)
+ public void tryToAutoDiscoverResourcePrivateNetworkInterfaceTestThrowConfigurationExceptionWhenThereIsNoValidNics() throws SocketException, ConfigurationException {
+ PowerMockito.mockStatic(NetworkInterface.class);
+ PowerMockito.when(NetworkInterface.getNetworkInterfaces()).thenReturn(Collections.enumeration(Arrays.asList(networkInterfaceMock1, networkInterfaceMock2)));
+ Mockito.doReturn(false).when(serverResourceBaseSpy).isValidNicToUseAsPrivateNic(Mockito.any());
+
+ serverResourceBaseSpy.tryToAutoDiscoverResourcePrivateNetworkInterface();
+
+ Mockito.verify(serverResourceBaseSpy, Mockito.times(2)).isValidNicToUseAsPrivateNic(Mockito.any());
+ }
+
+ @Test
+ @PrepareForTest(ServerResourceBase.class)
+ public void tryToAutoDiscoverResourcePrivateNetworkInterfaceTestReturnNic() throws SocketException, ConfigurationException {
+ Enumeration<NetworkInterface> interfaces = Collections.enumeration(Arrays.asList(networkInterfaceMock1, networkInterfaceMock2));
+
+ PowerMockito.mockStatic(NetworkInterface.class);
+ PowerMockito.when(NetworkInterface.getNetworkInterfaces()).thenReturn(interfaces);
+ Mockito.doReturn(false, true).when(serverResourceBaseSpy).isValidNicToUseAsPrivateNic(Mockito.any());
+
+ serverResourceBaseSpy.tryToAutoDiscoverResourcePrivateNetworkInterface();
+
+ Assert.assertEquals(networkInterfaceMock2, serverResourceBaseSpy._privateNic);
+ Mockito.verify(serverResourceBaseSpy, Mockito.times(2)).isValidNicToUseAsPrivateNic(Mockito.any());
+ }
+
+ @Test
+ @PrepareForTest(NetUtils.class)
+ public void defineResourceNetworkInterfacesTestUseXenbr0WhenPrivateNetworkInterfaceNotConfigured() {
+ Map<String, Object> params = createParamsMap(null, "cloudbr1", "cloudbr2", "cloudbr3");
+ PowerMockito.mockStatic(NetUtils.class);
+ PowerMockito.when(NetUtils.getNetworkInterface(Mockito.anyString())).thenReturn(networkInterfaceMock1, networkInterfaceMock2, networkInterfaceMock3, networkInterfaceMock4);
+
+ serverResourceBaseSpy.defineResourceNetworkInterfaces(params);
+
+ verifyAndAssertNetworkInterfaces("xenbr0", "cloudbr1", "cloudbr2", "cloudbr3");
+ }
+
+ @Test
+ @PrepareForTest(NetUtils.class)
+ public void defineResourceNetworkInterfacesTestUseXenbr1WhenPublicNetworkInterfaceNotConfigured() {
+ Map<String, Object> params = createParamsMap("cloudbr0", null, "cloudbr2", "cloudbr3");
+ PowerMockito.mockStatic(NetUtils.class);
+ PowerMockito.when(NetUtils.getNetworkInterface(Mockito.anyString())).thenReturn(networkInterfaceMock1, networkInterfaceMock2, networkInterfaceMock3, networkInterfaceMock4);
+
+ serverResourceBaseSpy.defineResourceNetworkInterfaces(params);
+
+ verifyAndAssertNetworkInterfaces("cloudbr0", "xenbr1", "cloudbr2", "cloudbr3");
+ }
+
+ @Test
+ @PrepareForTest(NetUtils.class)
+ public void defineResourceNetworkInterfacesTestUseConfiguredNetworkInterfaces() {
+ Map<String, Object> params = createParamsMap("cloudbr0", "cloudbr1", "cloudbr2", "cloudbr3");
+ PowerMockito.mockStatic(NetUtils.class);
+ PowerMockito.when(NetUtils.getNetworkInterface(Mockito.anyString())).thenReturn(networkInterfaceMock1, networkInterfaceMock2, networkInterfaceMock3, networkInterfaceMock4);
+
+ serverResourceBaseSpy.defineResourceNetworkInterfaces(params);
+
+ verifyAndAssertNetworkInterfaces("cloudbr0", "cloudbr1", "cloudbr2", "cloudbr3");
+ }
+
+ private Map<String, Object> createParamsMap(String... params) {
+ Map<String, Object> result = new HashMap<>();
+ result.put("private.network.device", params[0]);
+ result.put("public.network.device", params[1]);
+ result.put("storage.network.device", params[2]);
+ result.put("storage.network.device.2", params[3]);
+ return result;
+ }
+
+ private void verifyAndAssertNetworkInterfaces(String... expectedResults) {
+ PowerMockito.verifyStatic(NetUtils.class, Mockito.times(4));
+ NetUtils.getNetworkInterface(keyCaptor.capture());
+ List<String> keys = keyCaptor.getAllValues();
+
+ for (int i = 0; i < expectedResults.length; i++) {
+ Assert.assertEquals(expectedResults[i], keys.get(i));
+ }
+
+ Assert.assertEquals(networkInterfaceMock1, serverResourceBaseSpy._privateNic);
+ Assert.assertEquals(networkInterfaceMock2, serverResourceBaseSpy._publicNic);
+ Assert.assertEquals(networkInterfaceMock3, serverResourceBaseSpy._storageNic);
+ Assert.assertEquals(networkInterfaceMock4, serverResourceBaseSpy._storageNic2);
+ }
+}
diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
index 18ff8d42b16..8d8271a2fbe 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/BridgeVifDriver.java
@@ -35,6 +35,8 @@ import org.apache.log4j.Logger;
import org.libvirt.LibvirtException;
import com.cloud.agent.api.to.NicTO;
+import com.cloud.agent.properties.AgentProperties;
+import com.cloud.agent.properties.AgentPropertiesFileHandler;
import com.cloud.exception.InternalErrorException;
import com.cloud.network.Networks;
import com.cloud.utils.NumbersUtil;
@@ -61,10 +63,7 @@ public class BridgeVifDriver extends VifDriverBase {
// Set the domr scripts directory
params.put("domr.scripts.dir", "scripts/network/domr/kvm");
- String networkScriptsDir = (String)params.get("network.scripts.dir");
- if (networkScriptsDir == null) {
- networkScriptsDir = "scripts/vm/network/vnet";
- }
+ String networkScriptsDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.NETWORK_SCRIPTS_DIR);
String controlCidr = (String)params.get("control.cidr");
if (StringUtils.isNotBlank(controlCidr)) {
diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java
index 4c165f74a12..c0dceb3832d 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/IvsVifDriver.java
@@ -31,6 +31,8 @@ import org.apache.log4j.Logger;
import org.libvirt.LibvirtException;
import com.cloud.agent.api.to.NicTO;
+import com.cloud.agent.properties.AgentProperties;
+import com.cloud.agent.properties.AgentPropertiesFileHandler;
import com.cloud.exception.InternalErrorException;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef;
import com.cloud.network.Networks;
@@ -52,10 +54,8 @@ public class IvsVifDriver extends VifDriverBase {
@Override
public void configure(Map<String, Object> params) throws ConfigurationException {
super.configure(params);
- String networkScriptsDir = (String)params.get("network.scripts.dir");
- if (networkScriptsDir == null) {
- networkScriptsDir = "scripts/vm/network/vnet";
- }
+ String networkScriptsDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.NETWORK_SCRIPTS_DIR);
+
String utilScriptsDir = "scripts/util/";
String value = (String)params.get("scripts.timeout");
diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index bac5b89c39d..1d355d58f3d 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -22,6 +22,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.StringReader;
import java.net.InetAddress;
+import java.net.NetworkInterface;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
@@ -308,9 +309,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
private String _ovsPvlanVmPath;
private String _routerProxyPath;
private String _ovsTunnelPath;
- private String _host;
private String _dcId;
- private String _pod;
private String _clusterId;
private final Properties _uefiProperties = new Properties();
@@ -331,14 +330,11 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
public static final String SSHPUBKEYPATH = SSHKEYSPATH + File.separator + "id_rsa.pub.cloud";
public static final String DEFAULTDOMRSSHPORT = "3922";
- public final static String HOST_CACHE_PATH_PARAMETER = "host.cache.location";
public final static String CONFIG_DIR = "config";
private boolean enableIoUring;
- private final static String ENABLE_IO_URING_PROPERTY = "enable.io.uring";
public static final String BASH_SCRIPT_PATH = "/bin/bash";
- private String _mountPoint = "/mnt";
private StorageLayer _storage;
private KVMStoragePoolManager _storagePoolMgr;
@@ -759,40 +755,32 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
}
- private String getDefaultDirectDownloadTemporaryPath() {
- return "/var/lib/libvirt/images";
- }
-
- private String getDefaultCachePath() {
- return "/var/cache/cloud";
- }
-
- protected String getDefaultNetworkScriptsDir() {
- return "scripts/vm/network/vnet";
- }
-
- protected String getDefaultStorageScriptsDir() {
- return "scripts/storage/qcow2";
+ protected String getNetworkDirectSourceMode() {
+ return _networkDirectSourceMode;
}
- protected String getDefaultHypervisorScriptsDir() {
- return "scripts/vm/hypervisor";
+ protected String getNetworkDirectDevice() {
+ return _networkDirectDevice;
}
- protected String getDefaultKvmScriptsDir() {
- return "scripts/vm/hypervisor/kvm";
- }
+ /**
+ * Defines resource's public and private network interface according to what is configured in agent.properties.
+ */
+ @Override
+ protected void defineResourceNetworkInterfaces(Map<String, Object> params) {
+ _privBridgeName = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.PRIVATE_NETWORK_DEVICE);
+ _publicBridgeName = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.PUBLIC_NETWORK_DEVICE);
- protected String getDefaultDomrScriptsDir() {
- return "scripts/network/domr";
+ _privateNic = NetUtils.getNetworkInterface(_privBridgeName);
+ _publicNic = NetUtils.getNetworkInterface(_publicBridgeName);
}
- protected String getNetworkDirectSourceMode() {
- return _networkDirectSourceMode;
+ public NetworkInterface getPrivateNic() {
+ return _privateNic;
}
- protected String getNetworkDirectDevice() {
- return _networkDirectDevice;
+ public NetworkInterface getPublicNic() {
+ return _publicNic;
}
@Override
@@ -810,56 +798,31 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
_storage = new JavaStorageLayer();
_storage.configure("StorageLayer", params);
- String domrScriptsDir = (String)params.get("domr.scripts.dir");
- if (domrScriptsDir == null) {
- domrScriptsDir = getDefaultDomrScriptsDir();
- }
+ String domrScriptsDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.DOMR_SCRIPTS_DIR);
- String hypervisorScriptsDir = (String)params.get("hypervisor.scripts.dir");
- if (hypervisorScriptsDir == null) {
- hypervisorScriptsDir = getDefaultHypervisorScriptsDir();
- }
+ String hypervisorScriptsDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HYPERVISOR_SCRIPTS_DIR);
- String kvmScriptsDir = (String)params.get("kvm.scripts.dir");
- if (kvmScriptsDir == null) {
- kvmScriptsDir = getDefaultKvmScriptsDir();
- }
+ String kvmScriptsDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.KVM_SCRIPTS_DIR);
- String networkScriptsDir = (String)params.get("network.scripts.dir");
- if (networkScriptsDir == null) {
- networkScriptsDir = getDefaultNetworkScriptsDir();
- }
+ String networkScriptsDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.NETWORK_SCRIPTS_DIR);
- String storageScriptsDir = (String)params.get("storage.scripts.dir");
- if (storageScriptsDir == null) {
- storageScriptsDir = getDefaultStorageScriptsDir();
- }
+ String storageScriptsDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.STORAGE_SCRIPTS_DIR);
- final String bridgeType = (String)params.get("network.bridge.type");
- if (bridgeType == null) {
- _bridgeType = BridgeType.NATIVE;
- } else {
- _bridgeType = BridgeType.valueOf(bridgeType.toUpperCase());
- }
+ final String bridgeType = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.NETWORK_BRIDGE_TYPE);
+ _bridgeType = BridgeType.valueOf(bridgeType.toUpperCase());
- String dpdk = (String) params.get("openvswitch.dpdk.enabled");
- if (_bridgeType == BridgeType.OPENVSWITCH && Boolean.parseBoolean(dpdk)) {
+ Boolean dpdk = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.OPENVSWITCH_DPDK_ENABLED);
+ if (_bridgeType == BridgeType.OPENVSWITCH && BooleanUtils.isTrue(dpdk)) {
dpdkSupport = true;
- dpdkOvsPath = (String) params.get("openvswitch.dpdk.ovs.path");
+ dpdkOvsPath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.OPENVSWITCH_DPDK_OVS_PATH);
if (dpdkOvsPath != null && !dpdkOvsPath.endsWith("/")) {
dpdkOvsPath += "/";
}
}
- directDownloadTemporaryDownloadPath = (String) params.get("direct.download.temporary.download.location");
- if (StringUtils.isBlank(directDownloadTemporaryDownloadPath)) {
- directDownloadTemporaryDownloadPath = getDefaultDirectDownloadTemporaryPath();
- }
+ directDownloadTemporaryDownloadPath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.DIRECT_DOWNLOAD_TEMPORARY_DOWNLOAD_LOCATION);
- cachePath = (String) params.get(HOST_CACHE_PATH_PARAMETER);
- if (StringUtils.isBlank(cachePath)) {
- cachePath = getDefaultCachePath();
- }
+ cachePath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_CACHE_LOCATION);
params.put("domr.scripts.dir", domrScriptsDir);
@@ -870,22 +833,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
return false;
}
- _host = (String)params.get("host");
- if (_host == null) {
- _host = "localhost";
- }
-
- _dcId = (String)params.get("zone");
- if (_dcId == null) {
- _dcId = "default";
- }
-
- _pod = (String)params.get("pod");
- if (_pod == null) {
- _pod = "default";
- }
+ _dcId = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.ZONE);
- _clusterId = (String)params.get("cluster");
+ _clusterId = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CLUSTER);
_updateHostPasswdPath = Script.findScript(hypervisorScriptsDir, VRScripts.UPDATE_HOST_PASSWD);
if (_updateHostPasswdPath == null) {
@@ -962,9 +912,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
throw new ConfigurationException("Unable to find the ovs-pvlan-kvm-vm.sh");
}
- String value = (String)params.get("developer");
- final boolean isDeveloper = Boolean.parseBoolean(value);
-
+ final boolean isDeveloper = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.DEVELOPER);
if (isDeveloper) {
params.putAll(getDeveloperProperties());
}
@@ -974,42 +922,28 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
_pool = "/root";
}
- final String instance = (String)params.get("instance");
+ final String instance = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.INSTANCE);
- _hypervisorType = HypervisorType.getType((String)params.get("hypervisor.type"));
- if (_hypervisorType == HypervisorType.None) {
- _hypervisorType = HypervisorType.KVM;
- }
+ _hypervisorType = HypervisorType.getType(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HYPERVISOR_TYPE));
- String hooksDir = (String)params.get("rolling.maintenance.hooks.dir");
- value = (String) params.get("rolling.maintenance.service.executor.disabled");
- rollingMaintenanceExecutor = Boolean.parseBoolean(value) ? new RollingMaintenanceAgentExecutor(hooksDir) :
+ String hooksDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.ROLLING_MAINTENANCE_HOOKS_DIR);
+ rollingMaintenanceExecutor = BooleanUtils.isTrue(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.ROLLING_MAINTENANCE_SERVICE_EXECUTOR_DISABLED)) ? new RollingMaintenanceAgentExecutor(hooksDir) :
new RollingMaintenanceServiceExecutor(hooksDir);
- _hypervisorURI = (String)params.get("hypervisor.uri");
+ _hypervisorURI = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HYPERVISOR_URI);
if (_hypervisorURI == null) {
_hypervisorURI = LibvirtConnection.getHypervisorURI(_hypervisorType.toString());
}
- _networkDirectSourceMode = (String)params.get("network.direct.source.mode");
- _networkDirectDevice = (String)params.get("network.direct.device");
-
- String startMac = (String)params.get("private.macaddr.start");
- if (startMac == null) {
- startMac = "00:16:3e:77:e2:a0";
- }
-
- String startIp = (String)params.get("private.ipaddr.start");
- if (startIp == null) {
- startIp = "192.168.166.128";
- }
+ _networkDirectSourceMode = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.NETWORK_DIRECT_SOURCE_MODE);
+ _networkDirectDevice = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.NETWORK_DIRECT_DEVICE);
_pingTestPath = Script.findScript(kvmScriptsDir, "pingtest.sh");
if (_pingTestPath == null) {
throw new ConfigurationException("Unable to find the pingtest.sh");
}
- _linkLocalBridgeName = (String)params.get("private.bridge.name");
+ _linkLocalBridgeName = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.PRIVATE_BRIDGE_NAME);
if (_linkLocalBridgeName == null) {
if (isDeveloper) {
_linkLocalBridgeName = "cloud-" + instance + "-0";
@@ -1018,22 +952,12 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
}
- _publicBridgeName = (String)params.get("public.network.device");
- if (_publicBridgeName == null) {
- _publicBridgeName = "cloudbr0";
- }
-
- _privBridgeName = (String)params.get("private.network.device");
- if (_privBridgeName == null) {
- _privBridgeName = "cloudbr1";
- }
-
- _guestBridgeName = (String)params.get("guest.network.device");
+ _guestBridgeName = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_NETWORK_DEVICE);
if (_guestBridgeName == null) {
_guestBridgeName = _privBridgeName;
}
- _privNwName = (String)params.get("private.network.name");
+ _privNwName = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.PRIVATE_NETWORK_NAME);
if (_privNwName == null) {
if (isDeveloper) {
_privNwName = "cloud-" + instance + "-private";
@@ -1043,80 +967,54 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
enableSSLForKvmAgent(params);
- configureLocalStorage(params);
+ configureLocalStorage();
/* Directory to use for Qemu sockets like for the Qemu Guest Agent */
- _qemuSocketsPath = new File("/var/lib/libvirt/qemu");
- String _qemuSocketsPathVar = (String)params.get("qemu.sockets.path");
- if (_qemuSocketsPathVar != null && StringUtils.isNotBlank(_qemuSocketsPathVar)) {
- _qemuSocketsPath = new File(_qemuSocketsPathVar);
- }
+ String qemuSocketsPathVar = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.QEMU_SOCKETS_PATH);
+ _qemuSocketsPath = new File(qemuSocketsPathVar);
- value = (String)params.get("scripts.timeout");
+ // This value is never set. Default value is always used.
+ String value = (String)params.get("scripts.timeout");
_timeout = Duration.standardSeconds(NumbersUtil.parseInt(value, 30 * 60));
- value = (String)params.get("stop.script.timeout");
- _stopTimeout = NumbersUtil.parseInt(value, 120) * 1000;
+ _stopTimeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.STOP_SCRIPT_TIMEOUT) * 1000;
- value = (String)params.get("cmds.timeout");
- _cmdsTimeout = NumbersUtil.parseInt(value, 7200) * 1000;
+ _cmdsTimeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CMDS_TIMEOUT) * 1000;
- value = (String) params.get("vm.memballoon.disable");
- if (Boolean.parseBoolean(value)) {
- _noMemBalloon = true;
- }
+ _noMemBalloon = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MEMBALLOON_DISABLE);
+
+ _manualCpuSpeed = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_CPU_MANUAL_SPEED_MHZ);
- value = (String)params.get("host.cpu.manual.speed.mhz");
- _manualCpuSpeed = NumbersUtil.parseInt(value, 0);
+ _videoHw = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_VIDEO_HARDWARE);
- _videoHw = (String) params.get("vm.video.hardware");
- value = (String) params.get("vm.video.ram");
- _videoRam = NumbersUtil.parseInt(value, 0);
+ _videoRam = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_VIDEO_RAM);
- value = (String)params.get("host.reserved.mem.mb");
// Reserve 1GB unless admin overrides
- _dom0MinMem = NumbersUtil.parseInt(value, 1024) * 1024* 1024L;
+ _dom0MinMem = ByteScaleUtils.mebibytesToBytes(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_RESERVED_MEM_MB));
- value = (String)params.get("host.overcommit.mem.mb");
// Support overcommit memory for host if host uses ZSWAP, KSM and other memory
// compressing technologies
- _dom0OvercommitMem = NumbersUtil.parseInt(value, 0) * 1024 * 1024L;
+ _dom0OvercommitMem = ByteScaleUtils.mebibytesToBytes(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.HOST_OVERCOMMIT_MEM_MB));
- value = (String) params.get("kvmclock.disable");
- if (Boolean.parseBoolean(value)) {
+ if (BooleanUtils.isTrue(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.KVMCLOCK_DISABLE))) {
_noKvmClock = true;
}
- value = (String) params.get("vm.rng.enable");
- if (Boolean.parseBoolean(value)) {
+ if (BooleanUtils.isTrue(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_RNG_ENABLE))) {
_rngEnable = true;
- value = (String) params.get("vm.rng.model");
- if (StringUtils.isNotEmpty(value)) {
- _rngBackendModel = RngBackendModel.valueOf(value.toUpperCase());
- }
+ _rngBackendModel = RngBackendModel.valueOf(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_RNG_MODEL).toUpperCase());
- value = (String) params.get("vm.rng.path");
- if (StringUtils.isNotEmpty(value)) {
- _rngPath = value;
- }
+ _rngPath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_RNG_PATH);
- value = (String) params.get("vm.rng.rate.bytes");
- _rngRateBytes = NumbersUtil.parseInt(value, new Integer(_rngRateBytes));
+ _rngRateBytes = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_RNG_RATE_BYTES);
- value = (String) params.get("vm.rng.rate.period");
- _rngRatePeriod = NumbersUtil.parseInt(value, new Integer(_rngRatePeriod));
+ _rngRatePeriod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_RNG_RATE_PERIOD);
}
- value = (String) params.get("vm.watchdog.model");
- if (StringUtils.isNotEmpty(value)) {
- _watchDogModel = WatchDogModel.valueOf(value.toUpperCase());
- }
+ _watchDogModel = WatchDogModel.valueOf(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_WATCHDOG_MODEL).toUpperCase());
- value = (String) params.get("vm.watchdog.action");
- if (StringUtils.isNotEmpty(value)) {
- _watchDogAction = WatchDogAction.valueOf(value.toUpperCase());
- }
+ _watchDogAction = WatchDogAction.valueOf(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_WATCHDOG_ACTION).toUpperCase());
LibvirtConnection.initialize(_hypervisorURI);
Connect conn = null;
@@ -1165,20 +1063,19 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
// Enable/disable IO driver for Qemu (in case it is not set CloudStack can also detect if its supported by qemu)
- // Do not remove - switching it to AgentProperties.Property may require accepting null values for the properties default value
- String enableIoUringConfig = (String) params.get(ENABLE_IO_URING_PROPERTY);
+ Boolean enableIoUringConfig = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.ENABLE_IO_URING);
enableIoUring = isIoUringEnabled(enableIoUringConfig);
s_logger.info("IO uring driver for Qemu: " + (enableIoUring ? "enabled" : "disabled"));
- final String cpuArchOverride = (String)params.get("guest.cpu.arch");
+ final String cpuArchOverride = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_ARCH);
if (StringUtils.isNotEmpty(cpuArchOverride)) {
_guestCpuArch = cpuArchOverride;
s_logger.info("Using guest CPU architecture: " + _guestCpuArch);
}
- _guestCpuMode = (String)params.get("guest.cpu.mode");
+ _guestCpuMode = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_MODE);
if (_guestCpuMode != null) {
- _guestCpuModel = (String)params.get("guest.cpu.model");
+ _guestCpuModel = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_MODEL);
if (_hypervisorLibvirtVersion < 9 * 1000 + 10) {
s_logger.warn("Libvirt version 0.9.10 required for guest cpu mode, but version " + prettyVersion(_hypervisorLibvirtVersion) +
@@ -1190,7 +1087,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
params.put("guest.cpu.model", _guestCpuModel);
}
- final String cpuFeatures = (String)params.get("guest.cpu.features");
+ final String cpuFeatures = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_FEATURES);
if (cpuFeatures != null) {
_cpuFeatures = new ArrayList<String>();
for (final String feature: cpuFeatures.split(" ")) {
@@ -1249,24 +1146,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
s_logger.warn("No default IPv4 gateway found");
}
- _mountPoint = (String)params.get("mount.path");
- if (_mountPoint == null) {
- _mountPoint = "/mnt";
- }
-
- value = (String) params.get("vm.migrate.downtime");
- _migrateDowntime = NumbersUtil.parseInt(value, -1);
+ _migrateDowntime = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_DOWNTIME);
- value = (String) params.get("vm.migrate.pauseafter");
- _migratePauseAfter = NumbersUtil.parseInt(value, -1);
+ _migratePauseAfter = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_PAUSEAFTER);
- value = (String) params.get("vm.migrate.wait");
- _migrateWait = NumbersUtil.parseInt(value, -1);
+ _migrateWait = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_WAIT);
- configureAgentHooks(params);
+ configureAgentHooks();
- value = (String)params.get("vm.migrate.speed");
- _migrateSpeed = NumbersUtil.parseInt(value, -1);
+ _migrateSpeed = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_SPEED);
if (_migrateSpeed == -1) {
//get guest network device speed
_migrateSpeed = 0;
@@ -1292,15 +1180,15 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
getVifDriver(TrafficType.Control).createControlNetwork(_linkLocalBridgeName);
- configureDiskActivityChecks(params);
+ configureDiskActivityChecks();
final KVMStorageProcessor storageProcessor = new KVMStorageProcessor(_storagePoolMgr, this);
storageProcessor.configure(name, params);
storageHandler = new StorageSubsystemCommandHandlerBase(storageProcessor);
- Boolean _iscsiCleanUpEnabled = Boolean.parseBoolean((String)params.get("iscsi.session.cleanup.enabled"));
+ Boolean iscsiCleanUpEnabled = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.ISCSI_SESSION_CLEANUP_ENABLED);
- if (BooleanUtils.isTrue(_iscsiCleanUpEnabled)) {
+ if (BooleanUtils.isTrue(iscsiCleanUpEnabled)) {
IscsiStorageCleanupMonitor isciCleanupMonitor = new IscsiStorageCleanupMonitor();
final Thread cleanupMonitor = new Thread(isciCleanupMonitor);
cleanupMonitor.start();
@@ -1403,20 +1291,23 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
}
- protected void configureLocalStorage(final Map<String, Object> params) throws ConfigurationException {
- String localStoragePath = (String)params.get(LOCAL_STORAGE_PATH);
- if (localStoragePath == null) {
- localStoragePath = DEFAULT_LOCAL_STORAGE_PATH;
- }
- String localStorageUUIDString = (String)params.get(LOCAL_STORAGE_UUID);
+ protected void configureLocalStorage() throws ConfigurationException {
+ String localStoragePath = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_PATH);
+ s_logger.debug(String.format("Local Storage Path set: [%s].", localStoragePath));
+
+ String localStorageUUIDString = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LOCAL_STORAGE_UUID);
if (localStorageUUIDString == null) {
localStorageUUIDString = UUID.randomUUID().toString();
}
+ s_logger.debug(String.format("Local Storage UUID set: [%s].", localStorageUUIDString));
String[] localStorageRelativePaths = localStoragePath.split(CONFIG_VALUES_SEPARATOR);
String[] localStorageUUIDStrings = localStorageUUIDString.split(CONFIG_VALUES_SEPARATOR);
if (localStorageRelativePaths.length != localStorageUUIDStrings.length) {
- throw new ConfigurationException("The path and UUID of local storage pools have different length");
+ String errorMessage = String.format("The path and UUID of the local storage pools have different length. Path: [%s], UUID: [%s].", localStoragePath,
+ localStorageUUIDString);
+ s_logger.error(errorMessage);
+ throw new ConfigurationException(errorMessage);
}
for (String localStorageRelativePath : localStorageRelativePaths) {
final File storagePath = new File(localStorageRelativePath);
@@ -1449,10 +1340,9 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
// Save configurations in agent.properties
PropertiesStorage storage = new PropertiesStorage();
storage.configure("Storage", new HashMap<String, Object>());
- if (params.get("router.aggregation.command.each.timeout") != null) {
- String value = (String)params.get("router.aggregation.command.each.timeout");
- Long longValue = NumbersUtil.parseLong(value, 600);
- storage.persist("router.aggregation.command.each.timeout", String.valueOf(longValue));
+ Long longValue = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.ROUTER_AGGREGATION_COMMAND_EACH_TIMEOUT);
+ if (longValue != null) {
+ storage.persist(AgentProperties.ROUTER_AGGREGATION_COMMAND_EACH_TIMEOUT.getName(), String.valueOf(longValue));
}
if (params.get(Config.MigrateWait.toString()) != null) {
@@ -1465,47 +1355,26 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
return true;
}
- private void configureAgentHooks(final Map<String, Object> params) {
- String value = (String) params.get("agent.hooks.basedir");
- if (null != value) {
- _agentHooksBasedir = value;
- }
+ private void configureAgentHooks() {
+ _agentHooksBasedir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_BASEDIR);
s_logger.debug("agent.hooks.basedir is " + _agentHooksBasedir);
- value = (String) params.get("agent.hooks.libvirt_vm_xml_transformer.script");
- if (null != value) {
- _agentHooksLibvirtXmlScript = value;
- }
+ _agentHooksLibvirtXmlScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_SCRIPT);
s_logger.debug("agent.hooks.libvirt_vm_xml_transformer.script is " + _agentHooksLibvirtXmlScript);
- value = (String) params.get("agent.hooks.libvirt_vm_xml_transformer.method");
- if (null != value) {
- _agentHooksLibvirtXmlMethod = value;
- }
+ _agentHooksLibvirtXmlMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_XML_TRANSFORMER_METHOD);
s_logger.debug("agent.hooks.libvirt_vm_xml_transformer.method is " + _agentHooksLibvirtXmlMethod);
- value = (String) params.get("agent.hooks.libvirt_vm_on_start.script");
- if (null != value) {
- _agentHooksVmOnStartScript = value;
- }
+ _agentHooksVmOnStartScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_START_SCRIPT);
s_logger.debug("agent.hooks.libvirt_vm_on_start.script is " + _agentHooksVmOnStartScript);
- value = (String) params.get("agent.hooks.libvirt_vm_on_start.method");
- if (null != value) {
- _agentHooksVmOnStartMethod = value;
- }
+ _agentHooksVmOnStartMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_START_METHOD);
s_logger.debug("agent.hooks.libvirt_vm_on_start.method is " + _agentHooksVmOnStartMethod);
- value = (String) params.get("agent.hooks.libvirt_vm_on_stop.script");
- if (null != value) {
- _agentHooksVmOnStopScript = value;
- }
+ _agentHooksVmOnStopScript = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_STOP_SCRIPT);
s_logger.debug("agent.hooks.libvirt_vm_on_stop.script is " + _agentHooksVmOnStopScript);
- value = (String) params.get("agent.hooks.libvirt_vm_on_stop.method");
- if (null != value) {
- _agentHooksVmOnStopMethod = value;
- }
+ _agentHooksVmOnStopMethod = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.AGENT_HOOKS_LIBVIRT_VM_ON_STOP_METHOD);
s_logger.debug("agent.hooks.libvirt_vm_on_stop.method is " + _agentHooksVmOnStopMethod);
}
@@ -1538,14 +1407,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
}
}
- protected void configureDiskActivityChecks(final Map<String, Object> params) {
- _diskActivityCheckEnabled = Boolean.parseBoolean((String)params.get("vm.diskactivity.checkenabled"));
+ protected void configureDiskActivityChecks() {
+ _diskActivityCheckEnabled = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_DISKACTIVITY_CHECKENABLED);
if (_diskActivityCheckEnabled) {
- final int timeout = NumbersUtil.parseInt((String)params.get("vm.diskactivity.checktimeout_s"), 0);
+ final int timeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_DISKACTIVITY_CHECKTIMEOUT_S);
if (timeout > 0) {
_diskActivityCheckTimeoutSeconds = timeout;
}
- final long inactiveTime = NumbersUtil.parseLong((String)params.get("vm.diskactivity.inactivetime_ms"), 0L);
+ final long inactiveTime = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_DISKACTIVITY_INACTIVETIME_MS);
if (inactiveTime > 0) {
_diskActivityInactiveThresholdMilliseconds = inactiveTime;
}
@@ -1558,7 +1427,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
_trafficTypeVifDrivers = new HashMap<TrafficType, VifDriver>();
// Load the default vif driver
- String defaultVifDriverName = (String)params.get(LIBVIRT_VIF_DRIVER);
+ String defaultVifDriverName = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_VIF_DRIVER);
if (defaultVifDriverName == null) {
if (_bridgeType == BridgeType.OPENVSWITCH) {
s_logger.info("No libvirt.vif.driver specified. Defaults to OvsVifDriver.");
@@ -3194,14 +3063,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
/**
* IO_URING supported if the property 'enable.io.uring' is set to true OR it is supported by qemu
*/
- private boolean isIoUringEnabled(String enableIoUringConfig) {
+ private boolean isIoUringEnabled(Boolean enableIoUringConfig) {
boolean meetRequirements = getHypervisorLibvirtVersion() >= HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IO_URING
&& getHypervisorQemuVersion() >= HYPERVISOR_QEMU_VERSION_SUPPORTS_IO_URING;
if (!meetRequirements) {
return false;
}
return enableIoUringConfig != null ?
- Boolean.parseBoolean(enableIoUringConfig):
+ enableIoUringConfig:
(isBaseOsUbuntu() || isIoUringSupportedByQemu());
}
diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
index 05d33bc3418..c6867b3c146 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/OvsVifDriver.java
@@ -28,11 +28,14 @@ import com.cloud.hypervisor.kvm.dpdk.DpdkDriver;
import com.cloud.hypervisor.kvm.dpdk.DpdkDriverImpl;
import com.cloud.hypervisor.kvm.dpdk.DpdkHelper;
import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.libvirt.LibvirtException;
import com.cloud.agent.api.to.NicTO;
+import com.cloud.agent.properties.AgentProperties;
+import com.cloud.agent.properties.AgentPropertiesFileHandler;
import com.cloud.exception.InternalErrorException;
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef;
import com.cloud.network.Networks;
@@ -53,13 +56,7 @@ public class OvsVifDriver extends VifDriverBase {
getPifs();
- String networkScriptsDir = (String)params.get("network.scripts.dir");
- if (networkScriptsDir == null) {
- networkScriptsDir = "scripts/vm/network/vnet";
- }
-
- String dpdk = (String) params.get("openvswitch.dpdk.enabled");
- if (StringUtils.isNotBlank(dpdk) && Boolean.parseBoolean(dpdk)) {
+ if (BooleanUtils.isTrue(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.OPENVSWITCH_DPDK_ENABLED))) {
dpdkDriver = new DpdkDriverImpl();
}
diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
index 151e652e251..6a693a95a17 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
@@ -101,6 +101,8 @@ import com.cloud.agent.direct.download.HttpDirectTemplateDownloader;
import com.cloud.agent.direct.download.HttpsDirectTemplateDownloader;
import com.cloud.agent.direct.download.MetalinkDirectTemplateDownloader;
import com.cloud.agent.direct.download.NfsDirectTemplateDownloader;
+import com.cloud.agent.properties.AgentProperties;
+import com.cloud.agent.properties.AgentPropertiesFileHandler;
import com.cloud.exception.InternalErrorException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.hypervisor.Hypervisor;
@@ -123,7 +125,6 @@ import com.cloud.storage.template.Processor.FormatInfo;
import com.cloud.storage.template.QCOW2Processor;
import com.cloud.storage.template.TemplateConstants;
import com.cloud.storage.template.TemplateLocation;
-import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.UriUtils;
import com.cloud.utils.exception.CloudRuntimeException;
@@ -172,10 +173,7 @@ public class KVMStorageProcessor implements StorageProcessor {
storageLayer = new JavaStorageLayer();
storageLayer.configure("StorageLayer", params);
- String storageScriptsDir = (String)params.get("storage.scripts.dir");
- if (storageScriptsDir == null) {
- storageScriptsDir = getDefaultStorageScriptsDir();
- }
+ String storageScriptsDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.STORAGE_SCRIPTS_DIR);
_createTmplPath = Script.findScript(storageScriptsDir, "createtmplt.sh");
if (_createTmplPath == null) {
@@ -187,8 +185,7 @@ public class KVMStorageProcessor implements StorageProcessor {
throw new ConfigurationException("Unable to find the managesnapshot.sh");
}
- final String value = (String)params.get("cmds.timeout");
- _cmdsTimeout = NumbersUtil.parseInt(value, 7200) * 1000;
+ _cmdsTimeout = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.CMDS_TIMEOUT) * 1000;
return true;
}
diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
index 1d444b744be..7d2a9ea6b84 100644
--- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
+++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
+import java.net.NetworkInterface;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
@@ -57,6 +58,7 @@ import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
+import com.cloud.utils.net.NetUtils;
import org.apache.cloudstack.storage.command.AttachAnswer;
import org.apache.cloudstack.storage.command.AttachCommand;
import org.apache.cloudstack.utils.bytescale.ByteScaleUtils;
@@ -85,6 +87,7 @@ import org.libvirt.SchedUlongParameter;
import org.libvirt.StorageVol;
import org.libvirt.VcpuInfo;
import org.libvirt.jna.virDomainMemoryStats;
+import org.mockito.ArgumentCaptor;
import org.mockito.BDDMockito;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -227,7 +230,7 @@ import com.cloud.vm.VirtualMachine.Type;
public class LibvirtComputingResourceTest {
@Mock
- private LibvirtComputingResource libvirtComputingResource;
+ private LibvirtComputingResource libvirtComputingResourceMock;
@Mock
VirtualMachineTO vmTO;
@Mock
@@ -1024,7 +1027,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final StopCommand command = new StopCommand(vmName, false, false);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1034,11 +1037,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1058,7 +1061,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final StopCommand command = new StopCommand(vmName, false, true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
when(conn.domainLookupByName(command.getVmName())).thenReturn(vm);
@@ -1072,11 +1075,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(2)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1097,7 +1100,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final StopCommand command = new StopCommand(vmName, false, true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(LibvirtException.class);
when(conn.domainLookupByName(command.getVmName())).thenReturn(vm);
@@ -1111,11 +1114,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(2)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1135,7 +1138,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final StopCommand command = new StopCommand(vmName, false, true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
when(conn.domainLookupByName(command.getVmName())).thenReturn(vm);
@@ -1149,11 +1152,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1173,7 +1176,7 @@ public class LibvirtComputingResourceTest {
final GetVmStatsCommand command = new GetVmStatsCommand(vms, uuid, "hostname");
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1183,10 +1186,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1206,7 +1209,7 @@ public class LibvirtComputingResourceTest {
final GetVmDiskStatsCommand command = new GetVmDiskStatsCommand(vms, uuid, "hostname");
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnection()).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1216,10 +1219,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnection();
} catch (final LibvirtException e) {
@@ -1239,7 +1242,7 @@ public class LibvirtComputingResourceTest {
final GetVmDiskStatsCommand command = new GetVmDiskStatsCommand(vms, uuid, "hostname");
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnection()).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -1249,10 +1252,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnection();
} catch (final LibvirtException e) {
@@ -1268,7 +1271,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final RebootCommand command = new RebootCommand(vmName, true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1278,10 +1281,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1297,7 +1300,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final RebootCommand command = new RebootCommand(vmName, true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -1307,10 +1310,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1326,10 +1329,10 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final RebootCommand command = new RebootCommand(vmName, true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
- when(libvirtComputingResource.rebootVM(conn, command.getVmName())).thenReturn("error");
+ when(libvirtComputingResourceMock.rebootVM(conn, command.getVmName())).thenReturn("error");
} catch (final LibvirtException e) {
fail(e.getMessage());
}
@@ -1337,10 +1340,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1357,10 +1360,10 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final RebootCommand command = new RebootCommand(vmName, true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
- when(libvirtComputingResource.rebootVM(conn, command.getVmName())).thenThrow(LibvirtException.class);
+ when(libvirtComputingResourceMock.rebootVM(conn, command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
@@ -1368,10 +1371,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1388,8 +1391,8 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final RebootRouterCommand command = new RebootRouterCommand(vmName, "127.0.0.1");
- when(libvirtComputingResource.getVirtRouterResource()).thenReturn(routingResource);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getVirtRouterResource()).thenReturn(routingResource);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1399,12 +1402,12 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getVirtRouterResource();
+ verify(libvirtComputingResourceMock, times(1)).getVirtRouterResource();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1421,8 +1424,8 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final RebootRouterCommand command = new RebootRouterCommand(vmName, "127.0.0.1");
- when(libvirtComputingResource.getVirtRouterResource()).thenReturn(routingResource);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getVirtRouterResource()).thenReturn(routingResource);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(routingResource.connect(command.getPrivateIpAddress())).thenReturn(true);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
@@ -1433,11 +1436,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getVirtRouterResource();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getVirtRouterResource();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1455,9 +1458,9 @@ public class LibvirtComputingResourceTest {
final String uuid = "e8d6b4d0-bc6d-4613-b8bb-cb9e0600f3c6";
final GetHostStatsCommand command = new GetHostStatsCommand(uuid, "summer", 1l);
- when(libvirtComputingResource.getCPUStat()).thenReturn(cpuStat);
- when(libvirtComputingResource.getMemStat()).thenReturn(memStat);
- when(libvirtComputingResource.getNicStats(nullable(String.class))).thenReturn(new Pair<Double, Double>(1.0d, 1.0d));
+ when(libvirtComputingResourceMock.getCPUStat()).thenReturn(cpuStat);
+ when(libvirtComputingResourceMock.getMemStat()).thenReturn(memStat);
+ when(libvirtComputingResourceMock.getNicStats(nullable(String.class))).thenReturn(new Pair<Double, Double>(1.0d, 1.0d));
when(cpuStat.getCpuUsedPercent()).thenReturn(0.5d);
when(memStat.getAvailable()).thenReturn(1500L);
when(memStat.getTotal()).thenReturn(15000L);
@@ -1465,11 +1468,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getCPUStat();
- verify(libvirtComputingResource, times(1)).getMemStat();
+ verify(libvirtComputingResourceMock, times(1)).getCPUStat();
+ verify(libvirtComputingResourceMock, times(1)).getMemStat();
verify(cpuStat, times(1)).getCpuUsedPercent();
verify(memStat, times(1)).getAvailable();
verify(memStat, times(1)).getTotal();
@@ -1482,7 +1485,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -1499,7 +1502,7 @@ public class LibvirtComputingResourceTest {
final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1512,23 +1515,23 @@ public class LibvirtComputingResourceTest {
when(nicTO.getType()).thenReturn(TrafficType.Guest);
when(diskTO.getType()).thenReturn(Volume.Type.ISO);
- when(libvirtComputingResource.getVifDriver(nicTO.getType(), nicTO.getName())).thenReturn(vifDriver);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
+ when(libvirtComputingResourceMock.getVifDriver(nicTO.getType(), nicTO.getName())).thenReturn(vifDriver);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolManager);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(vm, times(1)).getNics();
verify(vm, times(1)).getDisks();
verify(diskTO, times(1)).getType();
@@ -1547,7 +1550,7 @@ public class LibvirtComputingResourceTest {
final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1560,24 +1563,24 @@ public class LibvirtComputingResourceTest {
when(nicTO.getType()).thenReturn(TrafficType.Guest);
when(diskTO.getType()).thenReturn(Volume.Type.ISO);
- when(libvirtComputingResource.getVifDriver(nicTO.getType(), nicTO.getName())).thenReturn(vifDriver);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
+ when(libvirtComputingResourceMock.getVifDriver(nicTO.getType(), nicTO.getName())).thenReturn(vifDriver);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolManager);
when(storagePoolManager.connectPhysicalDisksViaVmSpec(vm)).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(vm, times(1)).getNics();
verify(vm, times(1)).getDisks();
verify(diskTO, times(1)).getType();
@@ -1595,7 +1598,7 @@ public class LibvirtComputingResourceTest {
final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -1605,23 +1608,23 @@ public class LibvirtComputingResourceTest {
when(vm.getNics()).thenReturn(new NicTO[]{nicTO});
when(nicTO.getType()).thenReturn(TrafficType.Guest);
- when(libvirtComputingResource.getVifDriver(nicTO.getType())).thenReturn(vifDriver);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
+ when(libvirtComputingResourceMock.getVifDriver(nicTO.getType())).thenReturn(vifDriver);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolManager);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(vm, times(1)).getNics();
}
@@ -1639,7 +1642,7 @@ public class LibvirtComputingResourceTest {
final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1652,10 +1655,10 @@ public class LibvirtComputingResourceTest {
when(nicTO.getType()).thenReturn(TrafficType.Guest);
when(volume.getType()).thenReturn(Volume.Type.ISO);
- when(libvirtComputingResource.getVifDriver(nicTO.getType(), nicTO.getName())).thenReturn(vifDriver);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
+ when(libvirtComputingResourceMock.getVifDriver(nicTO.getType(), nicTO.getName())).thenReturn(vifDriver);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolManager);
try {
- when(libvirtComputingResource.getVolumePath(conn, volume)).thenThrow(URISyntaxException.class);
+ when(libvirtComputingResourceMock.getVolumePath(conn, volume)).thenThrow(URISyntaxException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final URISyntaxException e) {
@@ -1665,17 +1668,17 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(vm, times(1)).getNics();
verify(vm, times(1)).getDisks();
verify(volume, times(1)).getType();
@@ -1694,7 +1697,7 @@ public class LibvirtComputingResourceTest {
final PrepareForMigrationCommand command = new PrepareForMigrationCommand(vm);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vm.getName())).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1704,10 +1707,10 @@ public class LibvirtComputingResourceTest {
when(vm.getNics()).thenReturn(new NicTO[]{nicTO});
when(nicTO.getType()).thenReturn(TrafficType.Guest);
- BDDMockito.given(libvirtComputingResource.getVifDriver(nicTO.getType(), nicTO.getName())).willAnswer(invocationOnMock -> {throw new InternalErrorException("Exception Occurred");});
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolManager);
+ BDDMockito.given(libvirtComputingResourceMock.getVifDriver(nicTO.getType(), nicTO.getName())).willAnswer(invocationOnMock -> {throw new InternalErrorException("Exception Occurred");});
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolManager);
try {
- when(libvirtComputingResource.getVolumePath(conn, volume)).thenReturn("/path");
+ when(libvirtComputingResourceMock.getVolumePath(conn, volume)).thenReturn("/path");
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final URISyntaxException e) {
@@ -1717,17 +1720,17 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vm.getName());
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(vm, times(1)).getNics();
}
@@ -1745,7 +1748,7 @@ public class LibvirtComputingResourceTest {
DiskTO[] diskTOS = new DiskTO[]{};
final MigrateCommand command = new MigrateCommand(vmName, destIp, isWindows, vmTO, executeInSequence );
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(vmTO.getDisks()).thenReturn(diskTOS);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
@@ -1759,18 +1762,18 @@ public class LibvirtComputingResourceTest {
final List<InterfaceDef> ifaces = new ArrayList<InterfaceDef>();
ifaces.add(interfaceDef);
- when(libvirtComputingResource.getInterfaces(conn, vmName)).thenReturn(ifaces);
+ when(libvirtComputingResourceMock.getInterfaces(conn, vmName)).thenReturn(ifaces);
final DiskDef diskDef = Mockito.mock(DiskDef.class);
final List<DiskDef> disks = new ArrayList<DiskDef>();
disks.add(diskDef);
- when(libvirtComputingResource.getDisks(conn, vmName)).thenReturn(disks);
+ when(libvirtComputingResourceMock.getDisks(conn, vmName)).thenReturn(disks);
final Domain dm = Mockito.mock(Domain.class);
try {
when(conn.domainLookupByName(vmName)).thenReturn(dm);
- when(libvirtComputingResource.getPrivateIp()).thenReturn("127.0.0.1");
+ when(libvirtComputingResourceMock.getPrivateIp()).thenReturn("127.0.0.1");
when(dm.getXMLDesc(8)).thenReturn("<domain type='kvm' id='3'>" + " <devices>" + " <graphics type='vnc' port='5900' autoport='yes' listen='10.10.10.1'>"
+ " <listen type='address' address='10.10.10.1'/>" + " </graphics>" + " </devices>" + "</domain>");
when(dm.getXMLDesc(1)).thenReturn("<domain type='kvm' id='3'>" + " <devices>" + " <graphics type='vnc' port='5900' autoport='yes' listen='10.10.10.1'>"
@@ -1787,10 +1790,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
verify(libvirtUtilitiesHelper, times(1)).retrieveQemuConnection("qemu+tcp://" + command.getDestinationIp() + "/system");
@@ -1798,8 +1801,8 @@ public class LibvirtComputingResourceTest {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getInterfaces(conn, vmName);
- verify(libvirtComputingResource, times(1)).getDisks(conn, vmName);
+ verify(libvirtComputingResourceMock, times(1)).getInterfaces(conn, vmName);
+ verify(libvirtComputingResourceMock, times(1)).getDisks(conn, vmName);
try {
verify(conn, times(1)).domainLookupByName(vmName);
} catch (final LibvirtException e) {
@@ -1825,7 +1828,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -1836,7 +1839,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -1847,7 +1850,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -1859,22 +1862,22 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final CheckVirtualMachineCommand command = new CheckVirtualMachineCommand(vmName);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- when(libvirtComputingResource.getVmState(conn, command.getVmName())).thenReturn(PowerState.PowerOn);
+ when(libvirtComputingResourceMock.getVmState(conn, command.getVmName())).thenReturn(PowerState.PowerOn);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1891,22 +1894,22 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final CheckVirtualMachineCommand command = new CheckVirtualMachineCommand(vmName);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- when(libvirtComputingResource.getVmState(conn, command.getVmName())).thenReturn(PowerState.PowerOn);
+ when(libvirtComputingResourceMock.getVmState(conn, command.getVmName())).thenReturn(PowerState.PowerOn);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1921,7 +1924,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -1933,7 +1936,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -1943,10 +1946,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1962,7 +1965,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -1972,10 +1975,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -1991,7 +1994,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
BDDMockito.given(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).willAnswer(invocationOnMock -> {throw new URISyntaxException("Exception trying to get connection by VM name", vmName);});
} catch (final LibvirtException e) {
@@ -2001,10 +2004,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -2020,7 +2023,7 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final AttachIsoCommand command = new AttachIsoCommand(vmName, "/path", true);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
BDDMockito.given(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).willAnswer(invocationOnMock -> {throw new InternalErrorException("Exception Occurred");});
} catch (final LibvirtException e) {
@@ -2030,10 +2033,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -2054,7 +2057,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -2070,7 +2073,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -2081,7 +2084,7 @@ public class LibvirtComputingResourceTest {
final GetVncPortCommand command = new GetVncPortCommand(1l, "host");
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getName())).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -2091,10 +2094,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getName());
} catch (final LibvirtException e) {
@@ -2109,7 +2112,7 @@ public class LibvirtComputingResourceTest {
final GetVncPortCommand command = new GetVncPortCommand(1l, "host");
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -2119,10 +2122,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getName());
} catch (final LibvirtException e) {
@@ -2135,21 +2138,21 @@ public class LibvirtComputingResourceTest {
final ModifySshKeysCommand command = new ModifySshKeysCommand("", "");
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.retrieveSshKeysPath()).thenReturn("/path/keys");
when(libvirtUtilitiesHelper.retrieveSshPubKeyPath()).thenReturn("/path/pub/keys");
when(libvirtUtilitiesHelper.retrieveSshPrvKeyPath()).thenReturn("/path/pvt/keys");
- when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
+ when(libvirtComputingResourceMock.getTimeout()).thenReturn(Duration.ZERO);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getTimeout();
+ verify(libvirtComputingResourceMock, times(1)).getTimeout();
}
@Test
@@ -2159,7 +2162,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -2175,7 +2178,7 @@ public class LibvirtComputingResourceTest {
final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(primary.createPhysicalDisk(diskCharacteristics.getPath(), diskCharacteristics.getProvisioningType(), diskCharacteristics.getSize(), null)).thenReturn(vol);
@@ -2183,10 +2186,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
@@ -2203,19 +2206,19 @@ public class LibvirtComputingResourceTest {
final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(primary.getType()).thenReturn(StoragePoolType.CLVM);
- when(libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primary, diskCharacteristics.getPath())).thenReturn(vol);
+ when(libvirtComputingResourceMock.templateToPrimaryDownload(command.getTemplateUrl(), primary, diskCharacteristics.getPath())).thenReturn(vol);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
@@ -2233,7 +2236,7 @@ public class LibvirtComputingResourceTest {
final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class);
final KVMPhysicalDisk baseVol = Mockito.mock(KVMPhysicalDisk.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
when(primary.getPhysicalDisk(command.getTemplateUrl())).thenReturn(baseVol);
@@ -2242,10 +2245,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(pool.getType(), pool.getUuid());
}
@@ -2262,16 +2265,16 @@ public class LibvirtComputingResourceTest {
final VolumeTO vol = command.getVolume();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
@@ -2289,7 +2292,7 @@ public class LibvirtComputingResourceTest {
final VolumeTO vol = command.getVolume();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(poolManager);
when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
when(primary.deletePhysicalDisk(vol.getPath(), null)).thenThrow(CloudRuntimeException.class);
@@ -2297,10 +2300,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
@@ -2329,7 +2332,7 @@ public class LibvirtComputingResourceTest {
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByURI(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
@@ -2338,10 +2341,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test
@@ -2366,7 +2369,7 @@ public class LibvirtComputingResourceTest {
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByURI(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
@@ -2375,10 +2378,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test
@@ -2404,7 +2407,7 @@ public class LibvirtComputingResourceTest {
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByURI(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.listPhysicalDisks()).thenReturn(spiedDisks);
when(spiedDisks.isEmpty()).thenReturn(false);
@@ -2415,10 +2418,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test(expected = NullPointerException.class)
@@ -2441,7 +2444,7 @@ public class LibvirtComputingResourceTest {
final int index = url.lastIndexOf("/");
final String mountpoint = url.substring(0, index);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByURI(mountpoint)).thenReturn(secondaryPool);
when(secondaryPool.getPhysicalDisk("template.qcow2")).thenReturn(tmplVol);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
@@ -2450,10 +2453,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), command.getPoolUuid());
}
@@ -2465,16 +2468,16 @@ public class LibvirtComputingResourceTest {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(command.getPooltype(), command.getStorageId(), true)).thenReturn(secondaryPool);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePool(command.getPooltype(), command.getStorageId(), true);
}
@@ -2484,15 +2487,15 @@ public class LibvirtComputingResourceTest {
final DataStoreTO store = Mockito.mock(DataStoreTO.class);
final GetStorageStatsCommand command = new GetStorageStatsCommand(store );
- when(libvirtComputingResource.getStoragePoolMgr()).thenThrow(CloudRuntimeException.class);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenThrow(CloudRuntimeException.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test
@@ -2514,7 +2517,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -2526,16 +2529,16 @@ public class LibvirtComputingResourceTest {
final DeleteStoragePoolCommand command = new DeleteStoragePoolCommand(storagePool);
final StorageFilerTO pool = command.getPool();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).deleteStoragePool(pool.getType(), pool.getUuid());
}
@@ -2548,16 +2551,16 @@ public class LibvirtComputingResourceTest {
final DeleteStoragePoolCommand command = new DeleteStoragePoolCommand(storagePool);
final StorageFilerTO pool = command.getPool();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.deleteStoragePool(pool.getType(), pool.getUuid())).thenThrow(CloudRuntimeException.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).deleteStoragePool(pool.getType(), pool.getUuid());
}
@@ -2569,19 +2572,19 @@ public class LibvirtComputingResourceTest {
final OvsSetupBridgeCommand command = new OvsSetupBridgeCommand(name, hostId, networkId);
- when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
- when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
+ when(libvirtComputingResourceMock.configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
command.getBridgeName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
- verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
+ verify(libvirtComputingResourceMock, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
command.getBridgeName());
}
@@ -2593,19 +2596,19 @@ public class LibvirtComputingResourceTest {
final OvsSetupBridgeCommand command = new OvsSetupBridgeCommand(name, hostId, networkId);
- when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
- when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
+ when(libvirtComputingResourceMock.configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
command.getBridgeName())).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
- verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
+ verify(libvirtComputingResourceMock, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
command.getBridgeName());
}
@@ -2617,19 +2620,19 @@ public class LibvirtComputingResourceTest {
final OvsSetupBridgeCommand command = new OvsSetupBridgeCommand(name, hostId, networkId);
- when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(false);
- when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(false);
+ when(libvirtComputingResourceMock.configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
command.getBridgeName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
- verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
+ verify(libvirtComputingResourceMock, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getHostId(),
command.getBridgeName());
}
@@ -2641,16 +2644,16 @@ public class LibvirtComputingResourceTest {
final OvsDestroyBridgeCommand command = new OvsDestroyBridgeCommand(networkId, name, hostId);
- when(libvirtComputingResource.destroyTunnelNetwork(command.getBridgeName())).thenReturn(true);
+ when(libvirtComputingResourceMock.destroyTunnelNetwork(command.getBridgeName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).destroyTunnelNetwork(command.getBridgeName());
+ verify(libvirtComputingResourceMock, times(1)).destroyTunnelNetwork(command.getBridgeName());
}
@Test
@@ -2661,16 +2664,16 @@ public class LibvirtComputingResourceTest {
final OvsDestroyBridgeCommand command = new OvsDestroyBridgeCommand(networkId, name, hostId);
- when(libvirtComputingResource.destroyTunnelNetwork(command.getBridgeName())).thenReturn(false);
+ when(libvirtComputingResourceMock.destroyTunnelNetwork(command.getBridgeName())).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).destroyTunnelNetwork(command.getBridgeName());
+ verify(libvirtComputingResourceMock, times(1)).destroyTunnelNetwork(command.getBridgeName());
}
@Test
@@ -2682,7 +2685,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -2695,18 +2698,18 @@ public class LibvirtComputingResourceTest {
final OvsVpcPhysicalTopologyConfigCommand command = new OvsVpcPhysicalTopologyConfigCommand(hosts, tiers, vms, cidr);
- when(libvirtComputingResource.getOvsTunnelPath()).thenReturn("/path");
- when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
+ when(libvirtComputingResourceMock.getOvsTunnelPath()).thenReturn("/path");
+ when(libvirtComputingResourceMock.getTimeout()).thenReturn(Duration.ZERO);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getOvsTunnelPath();
- verify(libvirtComputingResource, times(1)).getTimeout();
+ verify(libvirtComputingResourceMock, times(1)).getOvsTunnelPath();
+ verify(libvirtComputingResourceMock, times(1)).getTimeout();
}
@SuppressWarnings("unchecked")
@@ -2719,15 +2722,15 @@ public class LibvirtComputingResourceTest {
final OvsVpcPhysicalTopologyConfigCommand command = new OvsVpcPhysicalTopologyConfigCommand(hosts, tiers, vms, cidr);
- when(libvirtComputingResource.getOvsTunnelPath()).thenThrow(Exception.class);
+ when(libvirtComputingResourceMock.getOvsTunnelPath()).thenThrow(Exception.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getOvsTunnelPath();
+ verify(libvirtComputingResourceMock, times(1)).getOvsTunnelPath();
}
@Test
@@ -2739,18 +2742,18 @@ public class LibvirtComputingResourceTest {
final OvsVpcRoutingPolicyConfigCommand command = new OvsVpcRoutingPolicyConfigCommand(id, cidr, acls, tiers);
- when(libvirtComputingResource.getOvsTunnelPath()).thenReturn("/path");
- when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
+ when(libvirtComputingResourceMock.getOvsTunnelPath()).thenReturn("/path");
+ when(libvirtComputingResourceMock.getTimeout()).thenReturn(Duration.ZERO);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getOvsTunnelPath();
- verify(libvirtComputingResource, times(1)).getTimeout();
+ verify(libvirtComputingResourceMock, times(1)).getOvsTunnelPath();
+ verify(libvirtComputingResourceMock, times(1)).getTimeout();
}
@SuppressWarnings("unchecked")
@@ -2763,15 +2766,15 @@ public class LibvirtComputingResourceTest {
final OvsVpcRoutingPolicyConfigCommand command = new OvsVpcRoutingPolicyConfigCommand(id, cidr, acls, tiers);
- when(libvirtComputingResource.getOvsTunnelPath()).thenThrow(Exception.class);
+ when(libvirtComputingResourceMock.getOvsTunnelPath()).thenThrow(Exception.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getOvsTunnelPath();
+ verify(libvirtComputingResourceMock, times(1)).getOvsTunnelPath();
}
@Test
@@ -2782,7 +2785,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -2794,7 +2797,8 @@ public class LibvirtComputingResourceTest {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
final KVMStoragePool kvmStoragePool = Mockito.mock(KVMStoragePool.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType(), command.getDetails())).thenReturn(kvmStoragePool);
@@ -2802,10 +2806,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType(), command.getDetails());
}
@@ -2817,7 +2821,7 @@ public class LibvirtComputingResourceTest {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType(), command.getDetails())).thenReturn(null);
@@ -2825,10 +2829,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool()
.getUserInfo(), command.getPool().getType(), command.getDetails());
}
@@ -2837,15 +2841,15 @@ public class LibvirtComputingResourceTest {
public void testCleanupNetworkRulesCmd() {
final CleanupNetworkRulesCmd command = new CleanupNetworkRulesCmd(1);
- when(libvirtComputingResource.cleanupRules()).thenReturn(true);
+ when(libvirtComputingResourceMock.cleanupRules()).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).cleanupRules();
+ verify(libvirtComputingResourceMock, times(1)).cleanupRules();
}
@Test
@@ -2860,18 +2864,18 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- when(libvirtComputingResource.configureNetworkRulesVMSecondaryIP(conn, command.getVmName(), command.getVmMac(), command.getVmSecIp(), command.getAction())).thenReturn(true);
+ when(libvirtComputingResourceMock.configureNetworkRulesVMSecondaryIP(conn, command.getVmName(), command.getVmMac(), command.getVmSecIp(), command.getAction())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
try {
@@ -2879,8 +2883,8 @@ public class LibvirtComputingResourceTest {
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
- verify(libvirtComputingResource, times(1)).configureNetworkRulesVMSecondaryIP(conn, command.getVmName(), command.getVmMac(), command.getVmSecIp(), command.getAction());
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).configureNetworkRulesVMSecondaryIP(conn, command.getVmName(), command.getVmMac(), command.getVmSecIp(), command.getAction());
}
@SuppressWarnings("unchecked")
@@ -2895,7 +2899,7 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -2904,7 +2908,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
try {
@@ -2912,7 +2916,7 @@ public class LibvirtComputingResourceTest {
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
}
@Test
@@ -2925,18 +2929,18 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
final Connect conn = Mockito.mock(Connect.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- when(libvirtComputingResource.configureDefaultNetworkRulesForSystemVm(conn, command.getVmName())).thenReturn(true);
+ when(libvirtComputingResourceMock.configureDefaultNetworkRulesForSystemVm(conn, command.getVmName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
try {
@@ -2944,8 +2948,8 @@ public class LibvirtComputingResourceTest {
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
- verify(libvirtComputingResource, times(1)).configureDefaultNetworkRulesForSystemVm(conn, command.getVmName());
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).configureDefaultNetworkRulesForSystemVm(conn, command.getVmName());
}
@SuppressWarnings("unchecked")
@@ -2958,7 +2962,7 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -2968,7 +2972,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
try {
@@ -2976,7 +2980,7 @@ public class LibvirtComputingResourceTest {
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
}
@Test
@@ -2992,16 +2996,16 @@ public class LibvirtComputingResourceTest {
final String privateIp = command.getIp();
final int cmdPort = command.getPort();
- when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
+ when(libvirtComputingResourceMock.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getVirtRouterResource();
+ verify(libvirtComputingResourceMock, times(1)).getVirtRouterResource();
verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
@@ -3018,16 +3022,16 @@ public class LibvirtComputingResourceTest {
final String privateIp = command.getIp();
final int cmdPort = command.getPort();
- when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
+ when(libvirtComputingResourceMock.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.connect(privateIp, cmdPort)).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getVirtRouterResource();
+ verify(libvirtComputingResourceMock, times(1)).getVirtRouterResource();
verify(virtRouterResource, times(1)).connect(privateIp, cmdPort);
}
@@ -3040,19 +3044,19 @@ public class LibvirtComputingResourceTest {
final CheckNetworkCommand command = new CheckNetworkCommand(networkInfoList);
- when(libvirtComputingResource.checkNetwork(TrafficType.Guest, nic.getGuestNetworkName())).thenReturn(true);
- when(libvirtComputingResource.checkNetwork(TrafficType.Management, nic.getPrivateNetworkName())).thenReturn(true);
- when(libvirtComputingResource.checkNetwork(TrafficType.Public, nic.getPublicNetworkName())).thenReturn(true);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Guest, nic.getGuestNetworkName())).thenReturn(true);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Management, nic.getPrivateNetworkName())).thenReturn(true);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Public, nic.getPublicNetworkName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).checkNetwork(TrafficType.Guest, nic.getGuestNetworkName());
- verify(libvirtComputingResource, times(1)).checkNetwork(TrafficType.Management, nic.getPrivateNetworkName());
- verify(libvirtComputingResource, times(1)).checkNetwork(TrafficType.Public, nic.getPublicNetworkName());
+ verify(libvirtComputingResourceMock, times(1)).checkNetwork(TrafficType.Guest, nic.getGuestNetworkName());
+ verify(libvirtComputingResourceMock, times(1)).checkNetwork(TrafficType.Management, nic.getPrivateNetworkName());
+ verify(libvirtComputingResourceMock, times(1)).checkNetwork(TrafficType.Public, nic.getPublicNetworkName());
}
@Test
@@ -3064,15 +3068,15 @@ public class LibvirtComputingResourceTest {
final CheckNetworkCommand command = new CheckNetworkCommand(networkInfoList);
- when(libvirtComputingResource.checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName())).thenReturn(false);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName())).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName());
+ verify(libvirtComputingResourceMock, times(1)).checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName());
}
@Test
@@ -3084,17 +3088,17 @@ public class LibvirtComputingResourceTest {
final CheckNetworkCommand command = new CheckNetworkCommand(networkInfoList);
- when(libvirtComputingResource.checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName())).thenReturn(true);
- when(libvirtComputingResource.checkNetwork(TrafficType.Management, networkSetupInfo.getPrivateNetworkName())).thenReturn(false);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName())).thenReturn(true);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Management, networkSetupInfo.getPrivateNetworkName())).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName());
- verify(libvirtComputingResource, times(1)).checkNetwork(TrafficType.Management, networkSetupInfo.getPrivateNetworkName());
+ verify(libvirtComputingResourceMock, times(1)).checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName());
+ verify(libvirtComputingResourceMock, times(1)).checkNetwork(TrafficType.Management, networkSetupInfo.getPrivateNetworkName());
}
@Test
@@ -3106,18 +3110,18 @@ public class LibvirtComputingResourceTest {
final CheckNetworkCommand command = new CheckNetworkCommand(networkInfoList);
- when(libvirtComputingResource.checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName())).thenReturn(true);
- when(libvirtComputingResource.checkNetwork(TrafficType.Management, networkSetupInfo.getPrivateNetworkName())).thenReturn(true);
- when(libvirtComputingResource.checkNetwork(TrafficType.Public, networkSetupInfo.getPublicNetworkName())).thenReturn(false);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName())).thenReturn(true);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Management, networkSetupInfo.getPrivateNetworkName())).thenReturn(true);
+ when(libvirtComputingResourceMock.checkNetwork(TrafficType.Public, networkSetupInfo.getPublicNetworkName())).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName());
- verify(libvirtComputingResource, times(1)).checkNetwork(TrafficType.Management, networkSetupInfo.getPrivateNetworkName());
+ verify(libvirtComputingResourceMock, times(1)).checkNetwork(TrafficType.Guest, networkSetupInfo.getGuestNetworkName());
+ verify(libvirtComputingResourceMock, times(1)).checkNetwork(TrafficType.Management, networkSetupInfo.getPrivateNetworkName());
}
@Test
@@ -3128,15 +3132,15 @@ public class LibvirtComputingResourceTest {
final OvsDestroyTunnelCommand command = new OvsDestroyTunnelCommand(networkId, networkName, inPortName);
- when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
}
@Test
@@ -3147,15 +3151,15 @@ public class LibvirtComputingResourceTest {
final OvsDestroyTunnelCommand command = new OvsDestroyTunnelCommand(networkId, networkName, inPortName);
- when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(false);
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(command.getBridgeName())).thenReturn(false);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
}
@SuppressWarnings("unchecked")
@@ -3167,15 +3171,15 @@ public class LibvirtComputingResourceTest {
final OvsDestroyTunnelCommand command = new OvsDestroyTunnelCommand(networkId, networkName, inPortName);
- when(libvirtComputingResource.findOrCreateTunnelNetwork(command.getBridgeName())).thenThrow(Exception.class);
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(command.getBridgeName())).thenThrow(Exception.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(command.getBridgeName());
}
@Test
@@ -3186,15 +3190,15 @@ public class LibvirtComputingResourceTest {
final KVMHAMonitor monitor = Mockito.mock(KVMHAMonitor.class);
- when(libvirtComputingResource.getMonitor()).thenReturn(monitor);
+ when(libvirtComputingResourceMock.getMonitor()).thenReturn(monitor);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getMonitor();
+ verify(libvirtComputingResourceMock, times(1)).getMonitor();
}
@Test
@@ -3212,19 +3216,19 @@ public class LibvirtComputingResourceTest {
final String bridge = command.getNetworkName();
- when(libvirtComputingResource.findOrCreateTunnelNetwork(bridge)).thenReturn(true);
- when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(bridge)).thenReturn(true);
+ when(libvirtComputingResourceMock.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
command.getNetworkName())).thenReturn(true);
- when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
+ when(libvirtComputingResourceMock.getTimeout()).thenReturn(Duration.ZERO);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(bridge);
- verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(bridge);
+ verify(libvirtComputingResourceMock, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
command.getNetworkName());
}
@@ -3243,18 +3247,18 @@ public class LibvirtComputingResourceTest {
final String bridge = command.getNetworkName();
- when(libvirtComputingResource.findOrCreateTunnelNetwork(bridge)).thenReturn(false);
- when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(bridge)).thenReturn(false);
+ when(libvirtComputingResourceMock.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
command.getNetworkName())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(bridge);
- verify(libvirtComputingResource, times(0)).configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(bridge);
+ verify(libvirtComputingResourceMock, times(0)).configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
command.getNetworkName());
}
@@ -3274,18 +3278,18 @@ public class LibvirtComputingResourceTest {
final String bridge = command.getNetworkName();
- when(libvirtComputingResource.findOrCreateTunnelNetwork(bridge)).thenReturn(true);
- when(libvirtComputingResource.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
+ when(libvirtComputingResourceMock.findOrCreateTunnelNetwork(bridge)).thenReturn(true);
+ when(libvirtComputingResourceMock.configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
command.getNetworkName())).thenThrow(Exception.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).findOrCreateTunnelNetwork(bridge);
- verify(libvirtComputingResource, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
+ verify(libvirtComputingResourceMock, times(1)).findOrCreateTunnelNetwork(bridge);
+ verify(libvirtComputingResourceMock, times(1)).configureTunnelNetwork(command.getNetworkId(), command.getFrom(),
command.getNetworkName());
}
@@ -3315,7 +3319,7 @@ public class LibvirtComputingResourceTest {
final String primaryUuid = command.getPrimaryStoragePoolNameLabel();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(secondaryPool);
when(secondaryPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), primaryUuid)).thenReturn(primaryPool);
@@ -3325,10 +3329,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
verify(secondaryPool, times(1)).getPhysicalDisk(command.getSnapshotName());
verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), primaryUuid);
@@ -3359,7 +3363,7 @@ public class LibvirtComputingResourceTest {
final String primaryUuid = command.getPrimaryStoragePoolNameLabel();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(secondaryPool);
when(secondaryPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), primaryUuid)).thenThrow(CloudRuntimeException.class);
@@ -3367,10 +3371,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
verify(secondaryPool, times(1)).getPhysicalDisk(command.getSnapshotName());
verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), primaryUuid);
@@ -3389,16 +3393,16 @@ public class LibvirtComputingResourceTest {
final List<NfsStoragePool> pools = new ArrayList<NfsStoragePool>();
pools.add(storagePool);
- when(libvirtComputingResource.getMonitor()).thenReturn(monitor);
+ when(libvirtComputingResourceMock.getMonitor()).thenReturn(monitor);
when(monitor.getStoragePools()).thenReturn(pools);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getMonitor();
+ verify(libvirtComputingResourceMock, times(1)).getMonitor();
verify(monitor, times(1)).getStoragePools();
}
@@ -3426,8 +3430,8 @@ public class LibvirtComputingResourceTest {
final InterfaceDef interfaceDef = Mockito.mock(InterfaceDef.class);
nics.add(interfaceDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getInterfaces(conn, command.getVmName())).thenReturn(nics);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -3447,10 +3451,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
@@ -3484,8 +3488,8 @@ public class LibvirtComputingResourceTest {
final InterfaceDef interfaceDef = Mockito.mock(InterfaceDef.class);
nics.add(interfaceDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getInterfaces(conn, command.getVmName())).thenReturn(nics);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
} catch (final LibvirtException e) {
@@ -3508,17 +3512,17 @@ public class LibvirtComputingResourceTest {
when(egressRuleSet[0].getEndPort()).thenReturn(22);
when(egressRuleSet[0].getAllowedCidrs()).thenReturn(cidrs);
- when(libvirtComputingResource.applyDefaultNetworkRules(conn, vm, true)).thenReturn(true);
- when(libvirtComputingResource.addNetworkRules(command.getVmName(), Long.toString(command.getVmId()), command.getGuestIp(), command.getGuestIp6(), command.getSignature(),
+ when(libvirtComputingResourceMock.applyDefaultNetworkRules(conn, vm, true)).thenReturn(true);
+ when(libvirtComputingResourceMock.addNetworkRules(command.getVmName(), Long.toString(command.getVmId()), command.getGuestIp(), command.getGuestIp6(), command.getSignature(),
Long.toString(command.getSeqNum()), command.getGuestMac(), command.stringifyRules(), vif, brname, command.getSecIpsString())).thenReturn(true);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
@@ -3549,8 +3553,8 @@ public class LibvirtComputingResourceTest {
final InterfaceDef interfaceDef = Mockito.mock(InterfaceDef.class);
nics.add(interfaceDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getInterfaces(conn, command.getVmName())).thenReturn(nics);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -3560,10 +3564,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
@@ -3587,8 +3591,8 @@ public class LibvirtComputingResourceTest {
final InterfaceDef intDef = Mockito.mock(InterfaceDef.class);
nics.add(intDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getInterfaces(conn, command.getVmName())).thenReturn(nics);
when(intDef.getDevName()).thenReturn("eth0");
when(intDef.getBrName()).thenReturn("br0");
@@ -3598,7 +3602,7 @@ public class LibvirtComputingResourceTest {
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
- when(libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
+ when(libvirtComputingResourceMock.getDomain(conn, instanceName)).thenReturn(vm);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
@@ -3606,13 +3610,13 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
- verify(libvirtComputingResource, times(1)).getDomain(conn, instanceName);
+ verify(libvirtComputingResourceMock, times(1)).getDomain(conn, instanceName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
@@ -3636,8 +3640,8 @@ public class LibvirtComputingResourceTest {
final InterfaceDef intDef = Mockito.mock(InterfaceDef.class);
nics.add(intDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getInterfaces(conn, command.getVmName())).thenReturn(nics);
when(intDef.getDevName()).thenReturn("eth0");
when(intDef.getBrName()).thenReturn("br0");
@@ -3648,9 +3652,9 @@ public class LibvirtComputingResourceTest {
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
- when(libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
+ when(libvirtComputingResourceMock.getDomain(conn, instanceName)).thenReturn(vm);
- when(libvirtComputingResource.getVifDriver(nic.getType(), nic.getName())).thenReturn(vifDriver);
+ when(libvirtComputingResourceMock.getVifDriver(nic.getType(), nic.getName())).thenReturn(vifDriver);
when(vifDriver.plug(nic, "Other PV", "", null)).thenReturn(interfaceDef);
when(interfaceDef.toString()).thenReturn("Interface");
@@ -3667,14 +3671,14 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
- verify(libvirtComputingResource, times(1)).getDomain(conn, instanceName);
- verify(libvirtComputingResource, times(1)).getVifDriver(nic.getType(), nic.getName());
+ verify(libvirtComputingResourceMock, times(1)).getDomain(conn, instanceName);
+ verify(libvirtComputingResourceMock, times(1)).getVifDriver(nic.getType(), nic.getName());
verify(vifDriver, times(1)).plug(nic, "Other PV", "", null);
} catch (final LibvirtException e) {
fail(e.getMessage());
@@ -3694,7 +3698,7 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
@@ -3705,10 +3709,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
@@ -3734,8 +3738,8 @@ public class LibvirtComputingResourceTest {
final InterfaceDef intDef = Mockito.mock(InterfaceDef.class);
nics.add(intDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getInterfaces(conn, command.getVmName())).thenReturn(nics);
when(intDef.getDevName()).thenReturn("eth0");
when(intDef.getBrName()).thenReturn("br0");
@@ -3745,9 +3749,9 @@ public class LibvirtComputingResourceTest {
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
- when(libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
+ when(libvirtComputingResourceMock.getDomain(conn, instanceName)).thenReturn(vm);
- when(libvirtComputingResource.getVifDriver(nic.getType(), nic.getName())).thenReturn(vifDriver);
+ when(libvirtComputingResourceMock.getVifDriver(nic.getType(), nic.getName())).thenReturn(vifDriver);
when(vifDriver.plug(nic, "Other PV", "", null)).thenThrow(InternalErrorException.class);
@@ -3760,14 +3764,14 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
- verify(libvirtComputingResource, times(1)).getDomain(conn, instanceName);
- verify(libvirtComputingResource, times(1)).getVifDriver(nic.getType(), nic.getName());
+ verify(libvirtComputingResourceMock, times(1)).getDomain(conn, instanceName);
+ verify(libvirtComputingResourceMock, times(1)).getVifDriver(nic.getType(), nic.getName());
verify(vifDriver, times(1)).plug(nic, "Other PV", "", null);
} catch (final LibvirtException e) {
fail(e.getMessage());
@@ -3796,8 +3800,8 @@ public class LibvirtComputingResourceTest {
final List<VifDriver> drivers = new ArrayList<VifDriver>();
drivers.add(vifDriver);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getInterfaces(conn, command.getVmName())).thenReturn(nics);
when(intDef.getDevName()).thenReturn("eth0");
when(intDef.getBrName()).thenReturn("br0");
@@ -3807,14 +3811,14 @@ public class LibvirtComputingResourceTest {
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
- when(libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
+ when(libvirtComputingResourceMock.getDomain(conn, instanceName)).thenReturn(vm);
when(interfaceDef.toString()).thenReturn("Interface");
final String interfaceDefStr = interfaceDef.toString();
doNothing().when(vm).detachDevice(interfaceDefStr);
- when(libvirtComputingResource.getAllVifDrivers()).thenReturn(drivers);
+ when(libvirtComputingResourceMock.getAllVifDrivers()).thenReturn(drivers);
doNothing().when(vifDriver).unplug(intDef, true);
@@ -3825,14 +3829,14 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
- verify(libvirtComputingResource, times(1)).getDomain(conn, instanceName);
- verify(libvirtComputingResource, times(1)).getAllVifDrivers();
+ verify(libvirtComputingResourceMock, times(1)).getDomain(conn, instanceName);
+ verify(libvirtComputingResourceMock, times(1)).getAllVifDrivers();
} catch (final LibvirtException e) {
fail(e.getMessage());
}
@@ -3855,12 +3859,12 @@ public class LibvirtComputingResourceTest {
final List<VifDriver> drivers = new ArrayList<VifDriver>();
drivers.add(vifDriver);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getInterfaces(conn, command.getVmName())).thenReturn(nics);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getInterfaces(conn, command.getVmName())).thenReturn(nics);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenReturn(conn);
- when(libvirtComputingResource.getDomain(conn, instanceName)).thenReturn(vm);
+ when(libvirtComputingResourceMock.getDomain(conn, instanceName)).thenReturn(vm);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
@@ -3868,13 +3872,13 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
- verify(libvirtComputingResource, times(1)).getDomain(conn, instanceName);
+ verify(libvirtComputingResourceMock, times(1)).getDomain(conn, instanceName);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
@@ -3890,7 +3894,7 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
@@ -3901,10 +3905,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
@@ -3921,18 +3925,18 @@ public class LibvirtComputingResourceTest {
final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, forVpc, gatewayIP);
- libvirtComputingResource.getNetworkStats(command.getPrivateIP());
+ libvirtComputingResourceMock.getNetworkStats(command.getPrivateIP());
- when(libvirtComputingResource.getNetworkStats(command.getPrivateIP())).thenReturn(new long[]{10l, 10l});
+ when(libvirtComputingResourceMock.getNetworkStats(command.getPrivateIP())).thenReturn(new long[]{10l, 10l});
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
//Being called twice, although I did not find the second place yet.
- verify(libvirtComputingResource, times(2)).getNetworkStats(command.getPrivateIP());
+ verify(libvirtComputingResourceMock, times(2)).getNetworkStats(command.getPrivateIP());
}
@Test
@@ -3943,17 +3947,17 @@ public class LibvirtComputingResourceTest {
final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, "create", forVpc);
- libvirtComputingResource.getNetworkStats(command.getPrivateIP());
+ libvirtComputingResourceMock.getNetworkStats(command.getPrivateIP());
- when(libvirtComputingResource.networkUsage(command.getPrivateIP(), "create", null)).thenReturn("SUCCESS");
+ when(libvirtComputingResourceMock.networkUsage(command.getPrivateIP(), "create", null)).thenReturn("SUCCESS");
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).networkUsage(command.getPrivateIP(), "create", null);
+ verify(libvirtComputingResourceMock, times(1)).networkUsage(command.getPrivateIP(), "create", null);
}
@Test
@@ -3966,17 +3970,17 @@ public class LibvirtComputingResourceTest {
final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, forVpc, gatewayIP, vpcCidr);
- libvirtComputingResource.getNetworkStats(command.getPrivateIP());
+ libvirtComputingResourceMock.getNetworkStats(command.getPrivateIP());
- when(libvirtComputingResource.configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), "create", command.getVpcCIDR())).thenReturn("SUCCESS");
+ when(libvirtComputingResourceMock.configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), "create", command.getVpcCIDR())).thenReturn("SUCCESS");
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), "create", command.getVpcCIDR());
+ verify(libvirtComputingResourceMock, times(1)).configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), "create", command.getVpcCIDR());
}
@Test
@@ -3988,17 +3992,17 @@ public class LibvirtComputingResourceTest {
final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, forVpc, gatewayIP);
- libvirtComputingResource.getNetworkStats(command.getPrivateIP());
+ libvirtComputingResourceMock.getNetworkStats(command.getPrivateIP());
- when(libvirtComputingResource.getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption())).thenReturn(new long[]{10l, 10l});
+ when(libvirtComputingResourceMock.getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption())).thenReturn(new long[]{10l, 10l});
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption());
+ verify(libvirtComputingResourceMock, times(1)).getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption());
}
@Test
@@ -4010,17 +4014,17 @@ public class LibvirtComputingResourceTest {
final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, "vpn", forVpc, gatewayIP);
- libvirtComputingResource.getNetworkStats(command.getPrivateIP());
+ libvirtComputingResourceMock.getNetworkStats(command.getPrivateIP());
- when(libvirtComputingResource.getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption())).thenReturn(new long[]{10l, 10l});
+ when(libvirtComputingResourceMock.getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption())).thenReturn(new long[]{10l, 10l});
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption());
+ verify(libvirtComputingResourceMock, times(1)).getVPCNetworkStats(command.getPrivateIP(), command.getGatewayIP(), command.getOption());
}
@Test
@@ -4032,17 +4036,17 @@ public class LibvirtComputingResourceTest {
final NetworkUsageCommand command = new NetworkUsageCommand(privateIP, domRName, null, forVpc, gatewayIP);
- libvirtComputingResource.getNetworkStats(command.getPrivateIP());
+ libvirtComputingResourceMock.getNetworkStats(command.getPrivateIP());
- when(libvirtComputingResource.configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), command.getOption(), command.getVpcCIDR())).thenReturn("FAILURE");
+ when(libvirtComputingResourceMock.configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), command.getOption(), command.getVpcCIDR())).thenReturn("FAILURE");
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), command.getOption(), command.getVpcCIDR());
+ verify(libvirtComputingResourceMock, times(1)).configureVPCNetworkUsage(command.getPrivateIP(), command.getGatewayIP(), command.getOption(), command.getVpcCIDR());
}
@Test
@@ -4066,17 +4070,17 @@ public class LibvirtComputingResourceTest {
final KVMStoragePool secondaryStorage = Mockito.mock(KVMStoragePool.class);
//final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePoolByURI(secondaryStorageUrl)).thenReturn(secondaryStorage);
when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel())).thenThrow(new CloudRuntimeException("error"));
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByURI(secondaryStorageUrl);
verify(storagePoolMgr, times(1)).getStoragePool(command.getPool().getType(), command.getPrimaryStoragePoolNameLabel());
}
@@ -4100,7 +4104,7 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
//final Connect conn = Mockito.mock(Connect.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
@@ -4111,10 +4115,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
@@ -4146,16 +4150,16 @@ public class LibvirtComputingResourceTest {
final StorageFilerTO pool = command.getPool();
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn);
- when(libvirtComputingResource.getDomain(conn, command.getVmName())).thenReturn(vm);
+ when(libvirtComputingResourceMock.getDomain(conn, command.getVmName())).thenReturn(vm);
when(vm.getInfo()).thenReturn(info);
} catch (final LibvirtException e) {
fail(e.getMessage());
}
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primaryPool);
when(primaryPool.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
when(primaryPool.isExternalSnapshot()).thenReturn(false);
@@ -4169,11 +4173,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName);
} catch (final LibvirtException e) {
@@ -4210,7 +4214,7 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
//final Connect conn = Mockito.mock(Connect.class);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName())).thenThrow(LibvirtException.class);
@@ -4221,10 +4225,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(command.getVmName());
} catch (final LibvirtException e) {
@@ -4262,7 +4266,7 @@ public class LibvirtComputingResourceTest {
final Processor qcow2Processor = Mockito.mock(Processor.class);
final FormatInfo info = Mockito.mock(FormatInfo.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
@@ -4272,16 +4276,16 @@ public class LibvirtComputingResourceTest {
when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
- when(libvirtComputingResource.getStorage()).thenReturn(storage);
+ when(libvirtComputingResourceMock.getStorage()).thenReturn(storage);
- when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
- when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
+ when(libvirtComputingResourceMock.createTmplPath()).thenReturn(templatePath);
+ when(libvirtComputingResourceMock.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
@@ -4297,10 +4301,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
@@ -4336,7 +4340,7 @@ public class LibvirtComputingResourceTest {
final Processor qcow2Processor = Mockito.mock(Processor.class);
final FormatInfo info = Mockito.mock(FormatInfo.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
@@ -4346,16 +4350,16 @@ public class LibvirtComputingResourceTest {
when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
- when(libvirtComputingResource.getStorage()).thenReturn(storage);
+ when(libvirtComputingResourceMock.getStorage()).thenReturn(storage);
- when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
- when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
+ when(libvirtComputingResourceMock.createTmplPath()).thenReturn(templatePath);
+ when(libvirtComputingResourceMock.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
@@ -4371,10 +4375,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
@@ -4409,7 +4413,7 @@ public class LibvirtComputingResourceTest {
final TemplateLocation location = Mockito.mock(TemplateLocation.class);
final Processor qcow2Processor = Mockito.mock(Processor.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
@@ -4419,16 +4423,16 @@ public class LibvirtComputingResourceTest {
when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
- when(libvirtComputingResource.getStorage()).thenReturn(storage);
+ when(libvirtComputingResourceMock.getStorage()).thenReturn(storage);
- when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
- when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
+ when(libvirtComputingResourceMock.createTmplPath()).thenReturn(templatePath);
+ when(libvirtComputingResourceMock.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
@@ -4444,10 +4448,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
@@ -4483,7 +4487,7 @@ public class LibvirtComputingResourceTest {
final Processor qcow2Processor = Mockito.mock(Processor.class);
final FormatInfo info = Mockito.mock(FormatInfo.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
@@ -4493,16 +4497,16 @@ public class LibvirtComputingResourceTest {
when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
when(secondaryPool.getLocalPath()).thenReturn(localPath);
- when(libvirtComputingResource.getStorage()).thenReturn(storage);
+ when(libvirtComputingResourceMock.getStorage()).thenReturn(storage);
- when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
- when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
+ when(libvirtComputingResourceMock.createTmplPath()).thenReturn(templatePath);
+ when(libvirtComputingResourceMock.getCmdsTimeout()).thenReturn(1);
final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
final String templateInstallFolder = "template/tmpl/" + templateFolder;
final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
@@ -4523,10 +4527,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
@@ -4555,13 +4559,13 @@ public class LibvirtComputingResourceTest {
final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
@@ -4571,10 +4575,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
@@ -4603,10 +4607,10 @@ public class LibvirtComputingResourceTest {
final StorageFilerTO pool = command.getPool();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(destVolumeName);
when(primary.getPhysicalDisk(command.getVolumePath())).thenReturn(disk);
when(storagePoolMgr.getStoragePoolByURI(secondaryStoragePoolURL)).thenReturn(secondary);
@@ -4620,10 +4624,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test
@@ -4650,9 +4654,9 @@ public class LibvirtComputingResourceTest {
final StorageFilerTO pool = command.getPool();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(destVolumeName);
when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
@@ -4663,10 +4667,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@SuppressWarnings("unchecked")
@@ -4693,9 +4697,9 @@ public class LibvirtComputingResourceTest {
final StorageFilerTO pool = command.getPool();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(primary);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(destVolumeName);
when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
@@ -4705,10 +4709,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test
@@ -4727,16 +4731,16 @@ public class LibvirtComputingResourceTest {
final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenThrow(new CloudRuntimeException("error"));
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test
@@ -4763,13 +4767,13 @@ public class LibvirtComputingResourceTest {
final StorageFilerTO pool = command.getPool();
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenThrow(new CloudRuntimeException("not found"));
when(storagePoolMgr.createStoragePool(pool.getUuid(), pool.getHost(), pool.getPort(), pool.getPath(),
pool.getUserInfo(), pool.getType())).thenReturn(primary);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(destVolumeName);
when(secondary.getType()).thenReturn(StoragePoolType.ManagedNFS);
when(secondary.getUuid()).thenReturn("60d979d8-d132-4181-8eca-8dfde50d7df6");
@@ -4780,10 +4784,10 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test
@@ -4798,16 +4802,16 @@ public class LibvirtComputingResourceTest {
final PvlanSetupCommand command = PvlanSetupCommand.createDhcpSetup(op, uri, networkTag, dhcpName, dhcpMac, dhcpIp);
final String guestBridgeName = "br0";
- when(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
- when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
+ when(libvirtComputingResourceMock.getGuestBridgeName()).thenReturn(guestBridgeName);
+ when(libvirtComputingResourceMock.getTimeout()).thenReturn(Duration.ZERO);
final String ovsPvlanDhcpHostPath = "/pvlan";
- when(libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
+ when(libvirtComputingResourceMock.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -4821,16 +4825,16 @@ public class LibvirtComputingResourceTest {
final PvlanSetupCommand command = PvlanSetupCommand.createVmSetup(op, uri, networkTag, vmMac);
final String guestBridgeName = "br0";
- when(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
- when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
+ when(libvirtComputingResourceMock.getGuestBridgeName()).thenReturn(guestBridgeName);
+ when(libvirtComputingResourceMock.getTimeout()).thenReturn(Duration.ZERO);
final String ovsPvlanVmPath = "/pvlan";
- when(libvirtComputingResource.getOvsPvlanVmPath()).thenReturn(ovsPvlanVmPath);
+ when(libvirtComputingResourceMock.getOvsPvlanVmPath()).thenReturn(ovsPvlanVmPath);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -4846,16 +4850,16 @@ public class LibvirtComputingResourceTest {
final PvlanSetupCommand command = PvlanSetupCommand.createDhcpSetup(op, uri, networkTag, dhcpName, dhcpMac, dhcpIp);
final String guestBridgeName = "br0";
- when(libvirtComputingResource.getGuestBridgeName()).thenReturn(guestBridgeName);
- when(libvirtComputingResource.getTimeout()).thenReturn(Duration.ZERO);
+ when(libvirtComputingResourceMock.getGuestBridgeName()).thenReturn(guestBridgeName);
+ when(libvirtComputingResourceMock.getTimeout()).thenReturn(Duration.ZERO);
final String ovsPvlanDhcpHostPath = "/pvlan";
- when(libvirtComputingResource.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
+ when(libvirtComputingResourceMock.getOvsPvlanDhcpHostPath()).thenReturn(ovsPvlanDhcpHostPath);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -4882,15 +4886,15 @@ public class LibvirtComputingResourceTest {
info.state = state;
when(pool.getType()).thenReturn(StoragePoolType.RBD);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
when(storagePool.getPhysicalDisk(path)).thenReturn(vol);
when(vol.getPath()).thenReturn(path);
- when(libvirtComputingResource.getResizeScriptType(storagePool, vol)).thenReturn("FILE");
+ when(libvirtComputingResourceMock.getResizeScriptType(storagePool, vol)).thenReturn("FILE");
when(storagePool.getType()).thenReturn(StoragePoolType.RBD);
when(vol.getFormat()).thenReturn(PhysicalDiskFormat.FILE);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnection()).thenReturn(conn);
when(conn.storageVolLookupByPath(path)).thenReturn(v);
@@ -4906,12 +4910,12 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(2)).getLibvirtUtilitiesHelper();
- verify(libvirtComputingResource, times(2)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnection();
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmInstance);
@@ -4942,14 +4946,14 @@ public class LibvirtComputingResourceTest {
info.state = state;
when(pool.getType()).thenReturn(StoragePoolType.Linstor);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
when(storagePool.getPhysicalDisk(path)).thenReturn(vol);
when(vol.getPath()).thenReturn(path);
when(storagePool.getType()).thenReturn(StoragePoolType.Linstor);
when(vol.getFormat()).thenReturn(PhysicalDiskFormat.RAW);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByVmName(vmInstance)).thenReturn(conn);
when(conn.domainLookupByName(vmInstance)).thenReturn(vm);
@@ -4961,13 +4965,13 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(0)).getResizeScriptType(storagePool, vol);
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(0)).getResizeScriptType(storagePool, vol);
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(0)).getConnection();
verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmInstance);
@@ -4990,7 +4994,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -5010,16 +5014,16 @@ public class LibvirtComputingResourceTest {
final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class);
when(pool.getType()).thenReturn(StoragePoolType.Filesystem);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
when(storagePool.getPhysicalDisk(path)).thenReturn(vol);
when(vol.getPath()).thenReturn(path);
- when(libvirtComputingResource.getResizeScriptType(storagePool, vol)).thenReturn("QCOW2");
+ when(libvirtComputingResourceMock.getResizeScriptType(storagePool, vol)).thenReturn("QCOW2");
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -5041,15 +5045,15 @@ public class LibvirtComputingResourceTest {
final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
when(pool.getType()).thenReturn(StoragePoolType.RBD);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
when(storagePool.getPhysicalDisk(path)).thenReturn(vol);
when(vol.getPath()).thenReturn(path);
- when(libvirtComputingResource.getResizeScriptType(storagePool, vol)).thenReturn("FILE");
+ when(libvirtComputingResourceMock.getResizeScriptType(storagePool, vol)).thenReturn("FILE");
when(storagePool.getType()).thenReturn(StoragePoolType.RBD);
when(vol.getFormat()).thenReturn(PhysicalDiskFormat.FILE);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnection()).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -5059,12 +5063,12 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnection();
} catch (final LibvirtException e) {
@@ -5088,17 +5092,17 @@ public class LibvirtComputingResourceTest {
final KVMStoragePool storagePool = Mockito.mock(KVMStoragePool.class);
when(pool.getType()).thenReturn(StoragePoolType.RBD);
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
when(storagePool.getPhysicalDisk(path)).thenThrow(CloudRuntimeException.class);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
}
@Test
@@ -5106,14 +5110,14 @@ public class LibvirtComputingResourceTest {
final CheckRouterCommand command = new CheckRouterCommand();
final VirtualRoutingResource virtRouterResource = Mockito.mock(VirtualRoutingResource.class);
- when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
+ when(libvirtComputingResourceMock.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.executeRequest(command)).thenReturn(new CheckRouterAnswer(command, "mock_resource"));
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -5124,14 +5128,14 @@ public class LibvirtComputingResourceTest {
final AttachCommand command = new AttachCommand(disk, vmName);
final StorageSubsystemCommandHandler handler = Mockito.mock(StorageSubsystemCommandHandler.class);
- when(libvirtComputingResource.getStorageHandler()).thenReturn(handler);
+ when(libvirtComputingResourceMock.getStorageHandler()).thenReturn(handler);
when(handler.handleStorageCommands(command)).thenReturn(new AttachAnswer(disk));
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -5153,16 +5157,16 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(vmSpec.getNics()).thenReturn(nics);
when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
when(vmSpec.getName()).thenReturn(vmName);
- when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
+ when(libvirtComputingResourceMock.createVMFromSpec(vmSpec)).thenReturn(vmDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
- doNothing().when(libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
+ doNothing().when(libvirtComputingResourceMock).createVbd(conn, vmSpec, vmName, vmDef);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
@@ -5176,11 +5180,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
} catch (final LibvirtException e) {
@@ -5206,13 +5210,13 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(vmSpec.getNics()).thenReturn(nics);
when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
when(vmSpec.getName()).thenReturn(vmName);
- when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
+ when(libvirtComputingResourceMock.createVMFromSpec(vmSpec)).thenReturn(vmDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenThrow(LibvirtException.class);
} catch (final LibvirtException e) {
@@ -5222,11 +5226,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
} catch (final LibvirtException e) {
@@ -5252,16 +5256,16 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(vmSpec.getNics()).thenReturn(nics);
when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
when(vmSpec.getName()).thenReturn(vmName);
- when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
+ when(libvirtComputingResourceMock.createVMFromSpec(vmSpec)).thenReturn(vmDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
- doThrow(InternalErrorException.class).when(libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
+ doThrow(InternalErrorException.class).when(libvirtComputingResourceMock).createVbd(conn, vmSpec, vmName, vmDef);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
@@ -5273,11 +5277,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
} catch (final LibvirtException e) {
@@ -5303,16 +5307,16 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(vmSpec.getNics()).thenReturn(nics);
when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
when(vmSpec.getName()).thenReturn(vmName);
- when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
+ when(libvirtComputingResourceMock.createVMFromSpec(vmSpec)).thenReturn(vmDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
- doThrow(URISyntaxException.class).when(libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
+ doThrow(URISyntaxException.class).when(libvirtComputingResourceMock).createVbd(conn, vmSpec, vmName, vmDef);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
@@ -5324,11 +5328,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
} catch (final LibvirtException e) {
@@ -5359,17 +5363,17 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final String controlIp = "127.0.0.1";
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(vmSpec.getNics()).thenReturn(nics);
when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
when(vmSpec.getName()).thenReturn(vmName);
- when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
+ when(libvirtComputingResourceMock.createVMFromSpec(vmSpec)).thenReturn(vmDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
when(conn.listDomains()).thenReturn(vms);
- doNothing().when(libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
+ doNothing().when(libvirtComputingResourceMock).createVbd(conn, vmSpec, vmName, vmDef);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
@@ -5380,16 +5384,16 @@ public class LibvirtComputingResourceTest {
when(storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)).thenReturn(true);
try {
- doNothing().when(libvirtComputingResource).createVifs(vmSpec, vmDef);
+ doNothing().when(libvirtComputingResourceMock).createVifs(vmSpec, vmDef);
- when(libvirtComputingResource.startVM(conn, vmName, vmDef.toString())).thenReturn("SUCCESS");
+ when(libvirtComputingResourceMock.startVM(conn, vmName, vmDef.toString())).thenReturn("SUCCESS");
when(vmSpec.getBootArgs()).thenReturn("ls -lart");
- when(libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs())).thenReturn(true);
+ when(libvirtComputingResourceMock.passCmdLine(vmName, vmSpec.getBootArgs())).thenReturn(true);
when(nic.getIp()).thenReturn(controlIp);
when(nic.getType()).thenReturn(TrafficType.Control);
- when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
+ when(libvirtComputingResourceMock.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.connect(controlIp, 1, 5000)).thenReturn(true);
when(virtRouterResource.isSystemVMSetup(vmName, controlIp)).thenReturn(true);
} catch (final InternalErrorException e) {
@@ -5401,11 +5405,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
} catch (final LibvirtException e) {
@@ -5436,17 +5440,17 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
final String controlIp = "127.0.0.1";
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(vmSpec.getNics()).thenReturn(nics);
when(vmSpec.getType()).thenReturn(VirtualMachine.Type.DomainRouter);
when(vmSpec.getName()).thenReturn(vmName);
- when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
+ when(libvirtComputingResourceMock.createVMFromSpec(vmSpec)).thenReturn(vmDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
when(conn.listDomains()).thenReturn(vms);
- doNothing().when(libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
+ doNothing().when(libvirtComputingResourceMock).createVbd(conn, vmSpec, vmName, vmDef);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
@@ -5457,20 +5461,20 @@ public class LibvirtComputingResourceTest {
when(storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec)).thenReturn(true);
try {
- doNothing().when(libvirtComputingResource).createVifs(vmSpec, vmDef);
+ doNothing().when(libvirtComputingResourceMock).createVifs(vmSpec, vmDef);
- when(libvirtComputingResource.startVM(conn, vmName, vmDef.toString())).thenReturn("SUCCESS");
+ when(libvirtComputingResourceMock.startVM(conn, vmName, vmDef.toString())).thenReturn("SUCCESS");
when(nic.isSecurityGroupEnabled()).thenReturn(true);
when(nic.getIsolationUri()).thenReturn(new URI("ec2://test"));
when(vmSpec.getBootArgs()).thenReturn("ls -lart");
- when(libvirtComputingResource.passCmdLine(vmName, vmSpec.getBootArgs())).thenReturn(true);
+ when(libvirtComputingResourceMock.passCmdLine(vmName, vmSpec.getBootArgs())).thenReturn(true);
when(nic.getIp()).thenReturn(controlIp);
when(nic.getType()).thenReturn(TrafficType.Control);
- when(libvirtComputingResource.getVirtRouterResource()).thenReturn(virtRouterResource);
+ when(libvirtComputingResourceMock.getVirtRouterResource()).thenReturn(virtRouterResource);
when(virtRouterResource.connect(controlIp, 1, 5000)).thenReturn(true);
when(virtRouterResource.isSystemVMSetup(vmName, controlIp)).thenReturn(true);
} catch (final InternalErrorException e) {
@@ -5484,11 +5488,11 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
- verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
- verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper();
+ verify(libvirtComputingResourceMock, times(1)).getStoragePoolMgr();
+ verify(libvirtComputingResourceMock, times(1)).getLibvirtUtilitiesHelper();
try {
verify(libvirtUtilitiesHelper, times(1)).getConnectionByType(vmDef.getHvsType());
} catch (final LibvirtException e) {
@@ -5517,21 +5521,21 @@ public class LibvirtComputingResourceTest {
final String vmName = "Test";
- when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
+ when(libvirtComputingResourceMock.getStoragePoolMgr()).thenReturn(storagePoolMgr);
when(vmSpec.getNics()).thenReturn(nics);
when(vmSpec.getType()).thenReturn(VirtualMachine.Type.User);
when(vmSpec.getName()).thenReturn(vmName);
when(vmSpec.getMaxRam()).thenReturn(512L);
- when(libvirtComputingResource.createVMFromSpec(vmSpec)).thenReturn(vmDef);
+ when(libvirtComputingResourceMock.createVMFromSpec(vmSpec)).thenReturn(vmDef);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
try {
when(libvirtUtilitiesHelper.getConnectionByType(vmDef.getHvsType())).thenReturn(conn);
when(conn.listDomains()).thenReturn(vms);
when(conn.domainLookupByID(vmId)).thenReturn(dm);
when(dm.getMaxMemory()).thenReturn(1024L);
when(dm.getName()).thenReturn(vmName);
- doNothing().when(libvirtComputingResource).createVbd(conn, vmSpec, vmName, vmDef);
+ doNothing().when(libvirtComputingResourceMock).createVbd(conn, vmSpec, vmName, vmDef);
} catch (final LibvirtException e) {
fail(e.getMessage());
} catch (final InternalErrorException e) {
@@ -5545,7 +5549,7 @@ public class LibvirtComputingResourceTest {
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -5561,16 +5565,16 @@ public class LibvirtComputingResourceTest {
final UpdateHostPasswordCommand command = new UpdateHostPasswordCommand(username, newPassword, hostIp);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getUpdateHostPasswdPath()).thenReturn("/tmp");
- when(libvirtUtilitiesHelper.buildScript(libvirtComputingResource.getUpdateHostPasswdPath())).thenReturn(script);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getUpdateHostPasswdPath()).thenReturn("/tmp");
+ when(libvirtUtilitiesHelper.buildScript(libvirtComputingResourceMock.getUpdateHostPasswdPath())).thenReturn(script);
when(script.execute()).thenReturn(null);
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertTrue(answer.getResult());
}
@@ -5586,16 +5590,16 @@ public class LibvirtComputingResourceTest {
final UpdateHostPasswordCommand command = new UpdateHostPasswordCommand(username, newPassword, hostIp);
- when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
- when(libvirtComputingResource.getUpdateHostPasswdPath()).thenReturn("/tmp");
- when(libvirtUtilitiesHelper.buildScript(libvirtComputingResource.getUpdateHostPasswdPath())).thenReturn(script);
+ when(libvirtComputingResourceMock.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
+ when(libvirtComputingResourceMock.getUpdateHostPasswdPath()).thenReturn("/tmp");
+ when(libvirtUtilitiesHelper.buildScript(libvirtComputingResourceMock.getUpdateHostPasswdPath())).thenReturn(script);
when(script.execute()).thenReturn("#FAIL");
final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
assertNotNull(wrapper);
- final Answer answer = wrapper.execute(command, libvirtComputingResource);
+ final Answer answer = wrapper.execute(command, libvirtComputingResourceMock);
assertFalse(answer.getResult());
}
@@ -5713,44 +5717,44 @@ public class LibvirtComputingResourceTest {
@Test
public void testUnknownCommand() {
- libvirtComputingResource = new LibvirtComputingResource();
+ libvirtComputingResourceMock = new LibvirtComputingResource();
Command cmd = new Command() {
@Override public boolean executeInSequence() {
return false;
}
};
- Answer ans = libvirtComputingResource.executeRequest(cmd);
+ Answer ans = libvirtComputingResourceMock.executeRequest(cmd);
assertTrue(ans instanceof UnsupportedAnswer);
}
@Test
public void testKnownCommand() {
- libvirtComputingResource = new LibvirtComputingResource();
+ libvirtComputingResourceMock = new LibvirtComputingResource();
Command cmd = new PingTestCommand() {
@Override public boolean executeInSequence() {
throw new NullPointerException("test succeeded");
}
};
- Answer ans = libvirtComputingResource.executeRequest(cmd);
+ Answer ans = libvirtComputingResourceMock.executeRequest(cmd);
assertFalse(ans instanceof UnsupportedAnswer);
assertTrue(ans instanceof Answer);
}
@Test
public void testAddExtraConfigComponentEmptyExtraConfig() {
- libvirtComputingResource = new LibvirtComputingResource();
- libvirtComputingResource.addExtraConfigComponent(new HashMap<>(), vmDef);
+ libvirtComputingResourceMock = new LibvirtComputingResource();
+ libvirtComputingResourceMock.addExtraConfigComponent(new HashMap<>(), vmDef);
Mockito.verify(vmDef, never()).addComp(any());
}
@Test
public void testAddExtraConfigComponentNotEmptyExtraConfig() {
- libvirtComputingResource = new LibvirtComputingResource();
+ libvirtComputingResourceMock = new LibvirtComputingResource();
Map<String, String> extraConfig = new HashMap<>();
extraConfig.put("extraconfig-1", "value1");
extraConfig.put("extraconfig-2", "value2");
extraConfig.put("extraconfig-3", "value3");
- libvirtComputingResource.addExtraConfigComponent(extraConfig, vmDef);
+ libvirtComputingResourceMock.addExtraConfigComponent(extraConfig, vmDef);
Mockito.verify(vmDef, times(1)).addComp(any());
}
@@ -5922,39 +5926,65 @@ public class LibvirtComputingResourceTest {
}));
}
- private void configLocalStorageTests(Map<String, Object> params) throws ConfigurationException {
- LibvirtComputingResource libvirtComputingResourceSpy = Mockito.spy(new LibvirtComputingResource());
- libvirtComputingResourceSpy.configureLocalStorage(params);
- }
-
@Test
public void testConfigureLocalStorageWithEmptyParams() throws ConfigurationException {
- Map<String, Object> params = new HashMap<>();
- configLocalStorageTests(params);
+ libvirtComputingResourceSpy.configureLocalStorage();
}
@Test
public void testConfigureLocalStorageWithMultiplePaths() throws ConfigurationException {
- Map<String, Object> params = new HashMap<>();
- params.put(LibvirtComputingResource.LOCAL_STORAGE_PATH, "/var/lib/libvirt/images/,/var/lib/libvirt/images2/");
- params.put(LibvirtComputingResource.LOCAL_STORAGE_UUID, UUID.randomUUID().toString() + "," + UUID.randomUUID().toString());
- configLocalStorageTests(params);
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.LOCAL_STORAGE_PATH))).thenReturn("/var/lib/libvirt/images/,/var/lib/libvirt/images2/");
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.LOCAL_STORAGE_UUID))).thenReturn(UUID.randomUUID().toString() + "," + UUID.randomUUID().toString());
+
+ libvirtComputingResourceSpy.configureLocalStorage();
}
@Test(expected = ConfigurationException.class)
- public void testConfigureLocalStorageWithDifferentLength() throws ConfigurationException {
- Map<String, Object> params = new HashMap<>();
- params.put(LibvirtComputingResource.LOCAL_STORAGE_PATH, "/var/lib/libvirt/images/,/var/lib/libvirt/images2/");
- params.put(LibvirtComputingResource.LOCAL_STORAGE_UUID, UUID.randomUUID().toString());
- configLocalStorageTests(params);
+ public void testConfigureLocalStorageWithDifferentLength() throws Exception {
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.LOCAL_STORAGE_PATH))).thenReturn("/var/lib/libvirt/images/,/var/lib/libvirt/images2/");
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.LOCAL_STORAGE_UUID))).thenReturn(UUID.randomUUID().toString());
+
+ libvirtComputingResourceSpy.configureLocalStorage();
}
@Test(expected = ConfigurationException.class)
public void testConfigureLocalStorageWithInvalidUUID() throws ConfigurationException {
- Map<String, Object> params = new HashMap<>();
- params.put(LibvirtComputingResource.LOCAL_STORAGE_PATH, "/var/lib/libvirt/images/");
- params.put(LibvirtComputingResource.LOCAL_STORAGE_UUID, "111111");
- configLocalStorageTests(params);
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.LOCAL_STORAGE_PATH))).thenReturn("/var/lib/libvirt/images/");
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.eq(AgentProperties.LOCAL_STORAGE_UUID))).thenReturn("111111");
+
+ libvirtComputingResourceSpy.configureLocalStorage();
+ }
+
+ @Test
+ @PrepareForTest({AgentPropertiesFileHandler.class, NetUtils.class})
+ public void defineResourceNetworkInterfacesTestUseProperties() {
+ NetworkInterface networkInterfaceMock1 = PowerMockito.mock(NetworkInterface.class);
+ NetworkInterface networkInterfaceMock2 = PowerMockito.mock(NetworkInterface.class);
+
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.when(AgentPropertiesFileHandler.getPropertyValue(Mockito.any())).thenReturn("cloudbr15", "cloudbr28");
+
+ PowerMockito.mockStatic(NetUtils.class);
+ PowerMockito.when(NetUtils.getNetworkInterface(Mockito.anyString())).thenReturn(networkInterfaceMock1, networkInterfaceMock2);
+
+ libvirtComputingResourceSpy.defineResourceNetworkInterfaces(null);
+
+ ArgumentCaptor<String> keyCaptor = ArgumentCaptor.forClass(String.class);
+ PowerMockito.verifyStatic(NetUtils.class, Mockito.times(2));
+ NetUtils.getNetworkInterface(keyCaptor.capture());
+
+ List<String> keys = keyCaptor.getAllValues();
+ Assert.assertEquals("cloudbr15", keys.get(0));
+ Assert.assertEquals("cloudbr28", keys.get(1));
+
+ Assert.assertEquals("cloudbr15", libvirtComputingResourceSpy._privBridgeName);
+ Assert.assertEquals("cloudbr28", libvirtComputingResourceSpy._publicBridgeName);
+
+ Assert.assertEquals(networkInterfaceMock1, libvirtComputingResourceSpy.getPrivateNic());
+ Assert.assertEquals(networkInterfaceMock2, libvirtComputingResourceSpy.getPublicNic());
}
@Test
diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVifDriverTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVifDriverTest.java
index 098352915a8..e3b74e84e1d 100644
--- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVifDriverTest.java
+++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVifDriverTest.java
@@ -36,15 +36,18 @@ import org.apache.cloudstack.utils.linux.MemStat;
import org.junit.Before;
import org.junit.Test;
+import com.cloud.agent.properties.AgentProperties;
+import com.cloud.agent.properties.AgentPropertiesFileHandler;
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource.BridgeType;
import com.cloud.network.Networks.TrafficType;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
-@PrepareForTest(value = {MemStat.class})
+@PrepareForTest(value = {MemStat.class, AgentPropertiesFileHandler.class})
public class LibvirtVifDriverTest {
private LibvirtComputingResource res;
@@ -132,40 +135,44 @@ public class LibvirtVifDriverTest {
}
@Test
- public void testDefaultsWhenExplicitlySet() throws ConfigurationException {
+ public void configureVifDriversTestWhenSetEqualToDefault() throws Exception {
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.doReturn(LibvirtComputingResource.DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME, LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS_NAME).when(AgentPropertiesFileHandler.class, "getPropertyValue", Mockito.eq(AgentProperties.LIBVIRT_VIF_DRIVER));
Map<String, Object> params = new HashMap<String, Object>();
// Switch res' bridge type for test purposes
- params.put(LibVirtVifDriver, LibvirtComputingResource.DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME);
res._bridgeType = BridgeType.NATIVE;
configure(params);
checkAllSame(bridgeVifDriver);
- params.clear();
- params.put(LibVirtVifDriver, LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS_NAME);
res._bridgeType = BridgeType.OPENVSWITCH;
configure(params);
checkAllSame(ovsVifDriver);
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.times(2));
+ AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_VIF_DRIVER);
}
@Test
- public void testWhenExplicitlySetDifferentDefault() throws ConfigurationException {
+ public void configureVifDriversTestWhenSetDifferentFromDefault() throws Exception {
+ PowerMockito.mockStatic(AgentPropertiesFileHandler.class);
+ PowerMockito.doReturn(LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS_NAME, LibvirtComputingResource.DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME).when(AgentPropertiesFileHandler.class, "getPropertyValue", Mockito.eq(AgentProperties.LIBVIRT_VIF_DRIVER));
// Tests when explicitly set vif driver to OVS when using regular bridges and vice versa
Map<String, Object> params = new HashMap<String, Object>();
// Switch res' bridge type for test purposes
- params.put(LibVirtVifDriver, LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS_NAME);
res._bridgeType = BridgeType.NATIVE;
configure(params);
checkAllSame(ovsVifDriver);
- params.clear();
- params.put(LibVirtVifDriver, LibvirtComputingResource.DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME);
res._bridgeType = BridgeType.OPENVSWITCH;
configure(params);
checkAllSame(bridgeVifDriver);
+
+ PowerMockito.verifyStatic(AgentPropertiesFileHandler.class, Mockito.times(2));
+ AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBVIRT_VIF_DRIVER);
}
@Test
diff --git a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh
index 3670010c5e9..05edc3fbf61 100755
--- a/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh
+++ b/systemvm/debian/opt/cloud/bin/setup/bootstrap.sh
@@ -18,6 +18,7 @@
set -x
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
CMDLINE=/var/cache/cloud/cmdline
+PROPERTIES=usr/local/cloud/systemvm/conf/agent.properties
rm -f /var/cache/cloud/enabled_svcs
rm -f /var/cache/cloud/disabled_svcs
@@ -42,7 +43,21 @@ patch_systemvm() {
mkdir -p /usr/local/cloud/systemvm
ls -lrt $patchfile
- echo "All" | unzip $patchfile -d /usr/local/cloud/systemvm >$logfile 2>&1
+ log_it "Unziping $patchfile"
+ echo "All" | unzip $patchfile -d /usr/local/cloud/systemvm >>$logfile 2>&1
+
+ if [ "$TYPE" = "secstorage" ]; then
+ log_it "As system VM type is $TYPE, we will remove the default properties 'instance' and 'resource' from $PROPERTIES"
+ sed -i '/instance=/d' $PROPERTIES
+ sed -i '/resource=/d' $PROPERTIES
+ fi
+
+ log_it "Copying content of $CMDLINE to $PROPERTIES"
+ for element in $(cat $CMDLINE)
+ do
+ echo $element >> $PROPERTIES
+ done
+
find /usr/local/cloud/systemvm/ -name \*.sh | xargs chmod 555
if [ -f $backupfolder/cloud.jks ]; then
cp -r $backupfolder/* /usr/local/cloud/systemvm/conf/
diff --git a/utils/src/main/java/com/cloud/utils/net/NetUtils.java b/utils/src/main/java/com/cloud/utils/net/NetUtils.java
index 8dd6df7e255..a6d9dfc51c2 100644
--- a/utils/src/main/java/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/main/java/com/cloud/utils/net/NetUtils.java
@@ -32,6 +32,7 @@ import java.net.SocketException;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Formatter;
import java.util.Iterator;
@@ -43,6 +44,7 @@ import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.net.util.SubnetUtils;
@@ -420,30 +422,49 @@ public class NetUtils {
}
}
- public static String[] getNetworkParams(final NetworkInterface nic) {
+ public static String[] getNetworkParams(NetworkInterface nic) {
+ s_logger.debug(String.format("Retrieving network params of NIC [%s].", nic));
+
+ s_logger.trace(String.format("Retrieving all NIC [%s] addresses.", nic));
List<InterfaceAddress> addrs = nic.getInterfaceAddresses();
- if (addrs == null || addrs.size() == 0) {
+ if (CollectionUtils.isEmpty(addrs)) {
+ s_logger.debug(String.format("NIC [%s] has no addresses, returning null.", nic));
return null;
}
- Collections.reverse(addrs); // reverse addresses because it has reverse order as "ip addr show"
+
+ String addrsToString = Arrays.toString(addrs.toArray());
+ s_logger.trace(String.format("Found [%s] as NIC [%s] addresses. Reversing the list order because it has reverse order in \"ip addr show\".",
+ addrsToString, nic));
+
+ Collections.reverse(addrs);
InterfaceAddress addr = null;
- for (final InterfaceAddress iaddr : addrs) {
- final InetAddress inet = iaddr.getAddress();
+
+ s_logger.trace(String.format("Iterating through the NIC [%s] addresses [%s] to find a valid address.", nic, addrsToString));
+ for (InterfaceAddress iaddr : addrs) {
+ InetAddress inet = iaddr.getAddress();
+ s_logger.trace(String.format("Validating address [%s].", inet));
if (!inet.isLinkLocalAddress() && !inet.isLoopbackAddress() && !inet.isMulticastAddress() && inet.getAddress().length == 4) {
addr = iaddr;
break;
}
+ s_logger.trace(String.format("Address [%s] is link local [%s], loopback [%s], multicast [%s], or does not have 4 octets [%s]; therefore we will not retrieve its" +
+ " interface params.", inet, inet.isLinkLocalAddress(), inet.isLoopbackAddress(), inet.isMulticastAddress(), inet.getAddress().length));
}
if (addr == null) {
+ s_logger.debug(String.format("Could not find a valid address in NIC [%s], returning null.", nic));
return null;
}
- final String[] result = new String[3];
+
+ s_logger.debug(String.format("Retrieving params of address [%s] of NIC [%s].", addr, nic));
+
+ String[] result = new String[3];
result[0] = addr.getAddress().getHostAddress();
+
try {
final byte[] mac = nic.getHardwareAddress();
result[1] = byte2Mac(mac);
} catch (final SocketException e) {
- s_logger.debug("Caught exception when trying to get the mac address ", e);
+ s_logger.warn(String.format("Unable to get NIC's [%s] MAC address due to [%s].", nic, e.getMessage()), e);
}
result[2] = prefix2Netmask(addr.getNetworkPrefixLength());
@@ -1727,4 +1748,27 @@ public class NetUtils {
return false;
}
+ public static NetworkInterface getNetworkInterface(String nicName) {
+ s_logger.debug(String.format("Retrieving network interface [%s].", nicName));
+ nicName = StringUtils.trimToNull(nicName);
+
+ if (nicName == null) {
+ return null;
+ }
+
+ NetworkInterface nic;
+ try {
+ nic = NetworkInterface.getByName(nicName);
+ if (nic == null) {
+ s_logger.debug(String.format("Unable to get network interface for NIC [%s].", nicName));
+ return null;
+ }
+
+ return nic;
+ } catch (final SocketException e) {
+ s_logger.warn(String.format("Unable to get network interface for NIC [%s] due to [%s].", nicName, e.getMessage()), e);
+ return null;
+ }
+ }
+
}
diff --git a/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java b/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
index 1eff484a278..2fa8496a235 100644
--- a/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
@@ -33,11 +33,13 @@ import static org.junit.Assert.assertTrue;
import java.math.BigInteger;
import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.SortedSet;
import java.util.TreeSet;
-import org.apache.log4j.Logger;
+import org.junit.Assert;
import org.junit.Test;
import com.cloud.utils.exception.CloudRuntimeException;
@@ -45,9 +47,17 @@ import com.cloud.utils.net.NetUtils.SupersetOrSubset;
import com.googlecode.ipv6.IPv6Address;
import com.googlecode.ipv6.IPv6Network;
-public class NetUtilsTest {
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
- private static final Logger s_logger = Logger.getLogger(NetUtilsTest.class);
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore({"jdk.xml.internal.*", "javax.xml.parsers.*", "org.xml.sax.*", "org.w3c.dom.*"})
+public class NetUtilsTest {
@Test
public void testGetRandomIpFromCidrWithSize24() throws Exception {
@@ -135,14 +145,12 @@ public class NetUtilsTest {
for (int i = 0; i < 5; i++) {
final String ip = NetUtils.getIp6FromRange("1234:5678::1-1234:5678::2");
assertThat(ip, anyOf(equalTo("1234:5678::1"), equalTo("1234:5678::2")));
- s_logger.info("IP is " + ip);
}
String ipString = null;
final IPv6Address ipStart = IPv6Address.fromString("1234:5678::1");
final IPv6Address ipEnd = IPv6Address.fromString("1234:5678::ffff:ffff:ffff:ffff");
for (int i = 0; i < 10; i++) {
ipString = NetUtils.getIp6FromRange(ipStart.toString() + "-" + ipEnd.toString());
- s_logger.info("IP is " + ipString);
final IPv6Address ip = IPv6Address.fromString(ipString);
assertThat(ip, greaterThanOrEqualTo(ipStart));
assertThat(ip, lessThanOrEqualTo(ipEnd));
@@ -741,4 +749,48 @@ public class NetUtilsTest {
assertEquals("255.255.0.0", NetUtils.cidr2Netmask("169.254.0.0/16"));
assertEquals("255.255.240.0", NetUtils.cidr2Netmask("169.254.240.0/20"));
}
+
+ @Test
+ public void getNetworkInterfaceTestReturnNullWhenStringIsNull() {
+ NetworkInterface result = NetUtils.getNetworkInterface(null);
+ Assert.assertNull(result);
+ }
+
+ @Test
+ public void getNetworkInterfaceTestReturnNullWhenStringIsEmpty() {
+ NetworkInterface result = NetUtils.getNetworkInterface(" ");
+ Assert.assertNull(result);
+ }
+
+ @Test
+ @PrepareForTest(NetUtils.class)
+ public void getNetworkInterfaceTestReturnNullWhenGetByNameReturnsNull() throws SocketException {
+ PowerMockito.mockStatic(NetworkInterface.class);
+ PowerMockito.when(NetworkInterface.getByName(Mockito.anyString())).thenReturn(null);
+ NetworkInterface result = NetUtils.getNetworkInterface(" test ");
+
+ Assert.assertNull(result);
+ }
+
+ @Test
+ @PrepareForTest(NetUtils.class)
+ public void getNetworkInterfaceTestReturnNullWhenGetByNameThrowsException() throws SocketException {
+ PowerMockito.mockStatic(NetworkInterface.class);
+ PowerMockito.when(NetworkInterface.getByName(Mockito.anyString())).thenThrow(SocketException.class);
+ NetworkInterface result = NetUtils.getNetworkInterface(" test ");
+
+ Assert.assertNull(result);
+ }
+
+ @Test
+ @PrepareForTest(NetUtils.class)
+ public void getNetworkInterfaceTestReturnInterfaceReturnedByGetByName() throws SocketException {
+ NetworkInterface expected = PowerMockito.mock(NetworkInterface.class);
+ PowerMockito.mockStatic(NetworkInterface.class);
+ PowerMockito.when(NetworkInterface.getByName(Mockito.anyString())).thenReturn(expected);
+
+ NetworkInterface result = NetUtils.getNetworkInterface(" test ");
+
+ Assert.assertEquals(expected, result);
+ }
}