Fix style for LibvirtComputingResource variable names and its dependencies (#7991)

* Fix style for LibvirtComputingResource variable names and its dependencies

* More variable name fixes

---------

Co-authored-by: Marcus Sorensen <mls@apple.com>
This commit is contained in:
Marcus Sorensen 2023-09-27 01:08:25 -06:00 committed by GitHub
parent f069c69807
commit 28c4be1cf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 617 additions and 617 deletions

View File

@ -83,16 +83,16 @@ import com.google.gson.Gson;
public class ConsoleProxyResource extends ServerResourceBase implements ServerResource { public class ConsoleProxyResource extends ServerResourceBase implements ServerResource {
static final Logger s_logger = Logger.getLogger(ConsoleProxyResource.class); static final Logger s_logger = Logger.getLogger(ConsoleProxyResource.class);
private final Properties _properties = new Properties(); private final Properties properties = new Properties();
private Thread _consoleProxyMain = null; private Thread consoleProxyMain = null;
long _proxyVmId; long proxyVmId;
int _proxyPort; int proxyPort;
String _localgw; String localGateway;
String _eth1ip; String eth1Ip;
String _eth1mask; String eth1Mask;
String _pubIp; String publicIp;
@Override @Override
public Answer executeRequest(final Command cmd) { public Answer executeRequest(final Command cmd) {
@ -203,10 +203,10 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
public synchronized StartupCommand[] initialize() { public synchronized StartupCommand[] initialize() {
final StartupProxyCommand cmd = new StartupProxyCommand(); final StartupProxyCommand cmd = new StartupProxyCommand();
fillNetworkInformation(cmd); fillNetworkInformation(cmd);
cmd.setProxyPort(_proxyPort); cmd.setProxyPort(proxyPort);
cmd.setProxyVmId(_proxyVmId); cmd.setProxyVmId(proxyVmId);
if (_pubIp != null) if (publicIp != null)
cmd.setPublicIpAddress(_pubIp); cmd.setPublicIpAddress(publicIp);
return new StartupCommand[] {cmd}; return new StartupCommand[] {cmd};
} }
@ -221,10 +221,10 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
@Override @Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_localgw = (String)params.get("localgw"); localGateway = (String)params.get("localgw");
_eth1mask = (String)params.get("eth1mask"); eth1Mask = (String)params.get("eth1mask");
_eth1ip = (String)params.get("eth1ip"); eth1Ip = (String)params.get("eth1ip");
if (_eth1ip != null) { if (eth1Ip != null) {
params.put("private.network.device", "eth1"); params.put("private.network.device", "eth1");
} else { } else {
s_logger.info("eth1ip parameter has not been configured, assuming that we are not inside a system vm"); s_logger.info("eth1ip parameter has not been configured, assuming that we are not inside a system vm");
@ -240,40 +240,40 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
super.configure(name, params); super.configure(name, params);
for (Map.Entry<String, Object> entry : params.entrySet()) { for (Map.Entry<String, Object> entry : params.entrySet()) {
_properties.put(entry.getKey(), entry.getValue()); properties.put(entry.getKey(), entry.getValue());
} }
String value = (String)params.get("premium"); String value = (String)params.get("premium");
if (value != null && value.equals("premium")) if (value != null && value.equals("premium"))
_proxyPort = 443; proxyPort = 443;
else { else {
value = (String)params.get("consoleproxy.httpListenPort"); value = (String)params.get("consoleproxy.httpListenPort");
_proxyPort = NumbersUtil.parseInt(value, 80); proxyPort = NumbersUtil.parseInt(value, 80);
} }
value = (String)params.get("proxy_vm"); value = (String)params.get("proxy_vm");
_proxyVmId = NumbersUtil.parseLong(value, 0); proxyVmId = NumbersUtil.parseLong(value, 0);
if (_localgw != null) { if (localGateway != null) {
String mgmtHosts = (String)params.get("host"); String mgmtHosts = (String)params.get("host");
if (_eth1ip != null) { if (eth1Ip != null) {
for (final String mgmtHost : mgmtHosts.split(",")) { for (final String mgmtHost : mgmtHosts.split(",")) {
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, mgmtHost); addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, mgmtHost);
} }
String internalDns1 = (String) params.get("internaldns1"); String internalDns1 = (String) params.get("internaldns1");
if (internalDns1 == null) { if (internalDns1 == null) {
s_logger.warn("No DNS entry found during configuration of ConsoleProxy"); s_logger.warn("No DNS entry found during configuration of ConsoleProxy");
} else { } else {
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns1); addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, internalDns1);
} }
String internalDns2 = (String) params.get("internaldns2"); String internalDns2 = (String) params.get("internaldns2");
if (internalDns2 != null) { if (internalDns2 != null) {
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns2); addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, internalDns2);
} }
} }
} }
_pubIp = (String)params.get("public.ip"); publicIp = (String)params.get("public.ip");
value = (String)params.get("disable_rp_filter"); value = (String)params.get("disable_rp_filter");
if (value != null && value.equalsIgnoreCase("true")) { if (value != null && value.equalsIgnoreCase("true")) {
@ -281,7 +281,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
} }
if (s_logger.isInfoEnabled()) if (s_logger.isInfoEnabled())
s_logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + _proxyVmId); s_logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + proxyVmId);
return true; return true;
} }
@ -301,7 +301,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
if (eth1ip != null && eth1mask != null) { if (eth1ip != null && eth1mask != null) {
inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr, eth1mask); inSameSubnet = NetUtils.sameSubnet(eth1ip, destIpOrCidr, eth1mask);
} else { } else {
s_logger.warn("addRouteToInternalIp: unable to determine same subnet: _eth1ip=" + eth1ip + ", dest ip=" + destIpOrCidr + ", _eth1mask=" + eth1mask); s_logger.warn("addRouteToInternalIp: unable to determine same subnet: eth1ip=" + eth1ip + ", dest ip=" + destIpOrCidr + ", eth1mask=" + eth1mask);
} }
} else { } else {
inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr, NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask)); inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr, NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask));
@ -327,15 +327,15 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
@Override @Override
public String getName() { public String getName() {
return _name; return name;
} }
private void launchConsoleProxy(final byte[] ksBits, final String ksPassword, final String encryptorPassword, final Boolean isSourceIpCheckEnabled) { private void launchConsoleProxy(final byte[] ksBits, final String ksPassword, final String encryptorPassword, final Boolean isSourceIpCheckEnabled) {
final Object resource = this; final Object resource = this;
s_logger.info("Building class loader for com.cloud.consoleproxy.ConsoleProxy"); s_logger.info("Building class loader for com.cloud.consoleproxy.ConsoleProxy");
if (_consoleProxyMain == null) { if (consoleProxyMain == null) {
s_logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password=" + encryptorPassword); s_logger.info("Running com.cloud.consoleproxy.ConsoleProxy with encryptor password=" + encryptorPassword);
_consoleProxyMain = new Thread(new ManagedContextRunnable() { consoleProxyMain = new Thread(new ManagedContextRunnable() {
@Override @Override
protected void runInContext() { protected void runInContext() {
try { try {
@ -343,7 +343,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
try { try {
s_logger.info("Invoke startWithContext()"); s_logger.info("Invoke startWithContext()");
Method method = consoleProxyClazz.getMethod("startWithContext", Properties.class, Object.class, byte[].class, String.class, String.class, Boolean.class); Method method = consoleProxyClazz.getMethod("startWithContext", Properties.class, Object.class, byte[].class, String.class, String.class, Boolean.class);
method.invoke(null, _properties, resource, ksBits, ksPassword, encryptorPassword, isSourceIpCheckEnabled); method.invoke(null, properties, resource, ksBits, ksPassword, encryptorPassword, isSourceIpCheckEnabled);
} catch (SecurityException e) { } catch (SecurityException e) {
s_logger.error("Unable to launch console proxy due to SecurityException", e); s_logger.error("Unable to launch console proxy due to SecurityException", e);
System.exit(ExitStatus.Error.value()); System.exit(ExitStatus.Error.value());
@ -366,8 +366,8 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
} }
} }
}, "Console-Proxy-Main"); }, "Console-Proxy-Main");
_consoleProxyMain.setDaemon(true); consoleProxyMain.setDaemon(true);
_consoleProxyMain.start(); consoleProxyMain.start();
} else { } else {
s_logger.info("com.cloud.consoleproxy.ConsoleProxy is already running"); s_logger.info("com.cloud.consoleproxy.ConsoleProxy is already running");
@ -430,27 +430,27 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
} }
public void reportLoadInfo(String gsonLoadInfo) { public void reportLoadInfo(String gsonLoadInfo) {
ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(_proxyVmId, gsonLoadInfo); ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(proxyVmId, gsonLoadInfo);
try { try {
getAgentControl().postRequest(cmd); getAgentControl().postRequest(cmd);
if (s_logger.isDebugEnabled()) if (s_logger.isDebugEnabled())
s_logger.debug("Report proxy load info, proxy : " + _proxyVmId + ", load: " + gsonLoadInfo); s_logger.debug("Report proxy load info, proxy : " + proxyVmId + ", load: " + gsonLoadInfo);
} catch (AgentControlChannelException e) { } catch (AgentControlChannelException e) {
s_logger.error("Unable to send out load info due to " + e.getMessage(), e); s_logger.error("Unable to send out load info due to " + e.getMessage(), e);
} }
} }
public void ensureRoute(String address) { public void ensureRoute(String address) {
if (_localgw != null) { if (localGateway != null) {
if (s_logger.isDebugEnabled()) if (s_logger.isDebugEnabled())
s_logger.debug("Ensure route for " + address + " via " + _localgw); s_logger.debug("Ensure route for " + address + " via " + localGateway);
// this method won't be called in high frequency, serialize access // this method won't be called in high frequency, serialize access
// to script execution // to script execution
synchronized (this) { synchronized (this) {
try { try {
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, address); addRouteToInternalIpOrCidr(localGateway, eth1Ip, eth1Mask, address);
} catch (Throwable e) { } catch (Throwable e) {
s_logger.warn("Unexpected exception while adding internal route to " + address, e); s_logger.warn("Unexpected exception while adding internal route to " + address, e);
} }

View File

@ -46,18 +46,18 @@ import com.cloud.utils.script.Script;
public abstract class ServerResourceBase implements ServerResource { public abstract class ServerResourceBase implements ServerResource {
private static final Logger s_logger = Logger.getLogger(ServerResourceBase.class); private static final Logger s_logger = Logger.getLogger(ServerResourceBase.class);
protected String _name; protected String name;
private ArrayList<String> _warnings = new ArrayList<String>(); private ArrayList<String> warnings = new ArrayList<String>();
private ArrayList<String> _errors = new ArrayList<String>(); private ArrayList<String> errors = new ArrayList<String>();
protected NetworkInterface _publicNic; protected NetworkInterface publicNic;
protected NetworkInterface _privateNic; protected NetworkInterface privateNic;
protected NetworkInterface _storageNic; protected NetworkInterface storageNic;
protected NetworkInterface _storageNic2; protected NetworkInterface storageNic2;
protected IAgentControl _agentControl; protected IAgentControl agentControl;
@Override @Override
public String getName() { public String getName() {
return _name; return name;
} }
protected String findScript(String script) { protected String findScript(String script) {
@ -68,15 +68,15 @@ public abstract class ServerResourceBase implements ServerResource {
@Override @Override
public boolean configure(final String name, Map<String, Object> params) throws ConfigurationException { public boolean configure(final String name, Map<String, Object> params) throws ConfigurationException {
_name = name; this.name = name;
defineResourceNetworkInterfaces(params); defineResourceNetworkInterfaces(params);
if (_privateNic == null) { if (privateNic == null) {
tryToAutoDiscoverResourcePrivateNetworkInterface(); tryToAutoDiscoverResourcePrivateNetworkInterface();
} }
String infos[] = NetUtils.getNetworkParams(_privateNic); String infos[] = NetUtils.getNetworkParams(privateNic);
if (infos == null) { if (infos == null) {
s_logger.warn("Incorrect details for private Nic during initialization of ServerResourceBase"); s_logger.warn("Incorrect details for private Nic during initialization of ServerResourceBase");
return false; return false;
@ -97,10 +97,10 @@ public abstract class ServerResourceBase implements ServerResource {
String storageNic = (String) params.get("storage.network.device"); String storageNic = (String) params.get("storage.network.device");
String storageNic2 = (String) params.get("storage.network.device.2"); String storageNic2 = (String) params.get("storage.network.device.2");
_privateNic = NetUtils.getNetworkInterface(privateNic); this.privateNic = NetUtils.getNetworkInterface(privateNic);
_publicNic = NetUtils.getNetworkInterface(publicNic); this.publicNic = NetUtils.getNetworkInterface(publicNic);
_storageNic = NetUtils.getNetworkInterface(storageNic); this.storageNic = NetUtils.getNetworkInterface(storageNic);
_storageNic2 = NetUtils.getNetworkInterface(storageNic2); this.storageNic2 = NetUtils.getNetworkInterface(storageNic2);
} }
protected void tryToAutoDiscoverResourcePrivateNetworkInterface() throws ConfigurationException { protected void tryToAutoDiscoverResourcePrivateNetworkInterface() throws ConfigurationException {
@ -121,7 +121,7 @@ public abstract class ServerResourceBase implements ServerResource {
for (NetworkInterface nic : nics) { for (NetworkInterface nic : nics) {
if (isValidNicToUseAsPrivateNic(nic)) { if (isValidNicToUseAsPrivateNic(nic)) {
s_logger.info(String.format("Using NIC [%s] as private NIC.", nic)); s_logger.info(String.format("Using NIC [%s] as private NIC.", nic));
_privateNic = nic; privateNic = nic;
return; return;
} }
} }
@ -152,8 +152,8 @@ public abstract class ServerResourceBase implements ServerResource {
protected void fillNetworkInformation(final StartupCommand cmd) { protected void fillNetworkInformation(final StartupCommand cmd) {
String[] info = null; String[] info = null;
if (_privateNic != null) { if (privateNic != null) {
info = NetUtils.getNetworkParams(_privateNic); info = NetUtils.getNetworkParams(privateNic);
if (info != null) { if (info != null) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Parameters for private nic: " + info[0] + " - " + info[1] + "-" + info[2]); s_logger.debug("Parameters for private nic: " + info[0] + " - " + info[1] + "-" + info[2]);
@ -164,11 +164,11 @@ public abstract class ServerResourceBase implements ServerResource {
} }
} }
if (_storageNic != null) { if (storageNic != null) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Storage has its now nic: " + _storageNic.getName()); s_logger.debug("Storage has its now nic: " + storageNic.getName());
} }
info = NetUtils.getNetworkParams(_storageNic); info = NetUtils.getNetworkParams(storageNic);
} }
// NOTE: In case you're wondering, this is not here by mistake. // NOTE: In case you're wondering, this is not here by mistake.
@ -181,8 +181,8 @@ public abstract class ServerResourceBase implements ServerResource {
cmd.setStorageNetmask(info[2]); cmd.setStorageNetmask(info[2]);
} }
if (_publicNic != null) { if (publicNic != null) {
info = NetUtils.getNetworkParams(_publicNic); info = NetUtils.getNetworkParams(publicNic);
if (info != null) { if (info != null) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Parameters for public nic: " + info[0] + " - " + info[1] + "-" + info[2]); s_logger.debug("Parameters for public nic: " + info[0] + " - " + info[1] + "-" + info[2]);
@ -193,8 +193,8 @@ public abstract class ServerResourceBase implements ServerResource {
} }
} }
if (_storageNic2 != null) { if (storageNic2 != null) {
info = NetUtils.getNetworkParams(_storageNic2); info = NetUtils.getNetworkParams(storageNic2);
if (info != null) { if (info != null) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Parameters for storage nic 2: " + info[0] + " - " + info[1] + "-" + info[2]); s_logger.debug("Parameters for storage nic 2: " + info[0] + " - " + info[1] + "-" + info[2]);
@ -212,18 +212,18 @@ public abstract class ServerResourceBase implements ServerResource {
@Override @Override
public IAgentControl getAgentControl() { public IAgentControl getAgentControl() {
return _agentControl; return agentControl;
} }
@Override @Override
public void setAgentControl(IAgentControl agentControl) { public void setAgentControl(IAgentControl agentControl) {
_agentControl = agentControl; this.agentControl = agentControl;
} }
protected void recordWarning(final String msg, final Throwable th) { protected void recordWarning(final String msg, final Throwable th) {
final String str = getLogStr(msg, th); final String str = getLogStr(msg, th);
synchronized (_warnings) { synchronized (warnings) {
_warnings.add(str); warnings.add(str);
} }
} }
@ -232,25 +232,25 @@ public abstract class ServerResourceBase implements ServerResource {
} }
protected List<String> getWarnings() { protected List<String> getWarnings() {
synchronized (_warnings) { synchronized (warnings) {
final List<String> results = new LinkedList<String>(_warnings); final List<String> results = new LinkedList<String>(warnings);
_warnings.clear(); warnings.clear();
return results; return results;
} }
} }
protected List<String> getErrors() { protected List<String> getErrors() {
synchronized (_errors) { synchronized (errors) {
final List<String> result = new LinkedList<String>(_errors); final List<String> result = new LinkedList<String>(errors);
_errors.clear(); errors.clear();
return result; return result;
} }
} }
protected void recordError(final String msg, final Throwable th) { protected void recordError(final String msg, final Throwable th) {
final String str = getLogStr(msg, th); final String str = getLogStr(msg, th);
synchronized (_errors) { synchronized (errors) {
_errors.add(str); errors.add(str);
} }
} }

View File

@ -170,7 +170,7 @@ public class ServerResourceBaseTest {
serverResourceBaseSpy.tryToAutoDiscoverResourcePrivateNetworkInterface(); serverResourceBaseSpy.tryToAutoDiscoverResourcePrivateNetworkInterface();
Assert.assertEquals(networkInterfaceMock2, serverResourceBaseSpy._privateNic); Assert.assertEquals(networkInterfaceMock2, serverResourceBaseSpy.privateNic);
Mockito.verify(serverResourceBaseSpy, Mockito.times(2)).isValidNicToUseAsPrivateNic(Mockito.any()); Mockito.verify(serverResourceBaseSpy, Mockito.times(2)).isValidNicToUseAsPrivateNic(Mockito.any());
} }
} }
@ -229,9 +229,9 @@ public class ServerResourceBaseTest {
Assert.assertEquals(expectedResults[i], keys.get(i)); Assert.assertEquals(expectedResults[i], keys.get(i));
} }
Assert.assertEquals(networkInterfaceMock1, serverResourceBaseSpy._privateNic); Assert.assertEquals(networkInterfaceMock1, serverResourceBaseSpy.privateNic);
Assert.assertEquals(networkInterfaceMock2, serverResourceBaseSpy._publicNic); Assert.assertEquals(networkInterfaceMock2, serverResourceBaseSpy.publicNic);
Assert.assertEquals(networkInterfaceMock3, serverResourceBaseSpy._storageNic); Assert.assertEquals(networkInterfaceMock3, serverResourceBaseSpy.storageNic);
Assert.assertEquals(networkInterfaceMock4, serverResourceBaseSpy._storageNic2); Assert.assertEquals(networkInterfaceMock4, serverResourceBaseSpy.storageNic2);
} }
} }

View File

@ -166,34 +166,34 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
private static final Logger s_logger = Logger.getLogger(HypervDirectConnectResource.class.getName()); private static final Logger s_logger = Logger.getLogger(HypervDirectConnectResource.class.getName());
private static final Gson s_gson = GsonHelper.getGson(); private static final Gson s_gson = GsonHelper.getGson();
private String _zoneId; private String zoneId;
private String _podId; private String podId;
private String _clusterId; private String clusterId;
private String _guid; private String guid;
private String _agentIp; private String agentIp;
private final int _port = DEFAULT_AGENT_PORT; private final int port = DEFAULT_AGENT_PORT;
protected final long _opsTimeout = 900000; // 15 minutes time out to time protected final long opsTimeout = 900000; // 15 minutes time out to time
protected final int _retry = 24; protected final int retry = 24;
protected final int _sleep = 10000; protected final int sleep = 10000;
protected static final int DEFAULT_DOMR_SSHPORT = 3922; protected static final int DEFAULT_DOMR_SSHPORT = 3922;
private String _clusterGuid; private String clusterGuid;
// Used by initialize to assert object configured before // Used by initialize to assert object configured before
// initialize called. // initialize called.
private boolean _configureCalled = false; private boolean configureCalled = false;
private String _username; private String username;
private String _password; private String password;
private static HypervManager s_hypervMgr; private static HypervManager s_hypervMgr;
@Inject @Inject
HypervManager _hypervMgr; HypervManager hypervManager;
protected VirtualRoutingResource _vrResource; protected VirtualRoutingResource vrResource;
@PostConstruct @PostConstruct
void init() { void init() {
s_hypervMgr = _hypervMgr; s_hypervMgr = hypervManager;
} }
@Override @Override
@ -204,7 +204,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
@Override @Override
public final StartupCommand[] initialize() { public final StartupCommand[] initialize() {
// assert // assert
if (!_configureCalled) { if (!configureCalled) {
final String errMsg = this.getClass().getName() + " requires configure() be called before" + " initialize()"; final String errMsg = this.getClass().getName() + " requires configure() be called before" + " initialize()";
s_logger.error(errMsg); s_logger.error(errMsg);
} }
@ -215,16 +215,16 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
// Identity within the data centre is decided by CloudStack kernel, // Identity within the data centre is decided by CloudStack kernel,
// and passed via ServerResource.configure() // and passed via ServerResource.configure()
defaultStartRoutCmd.setDataCenter(_zoneId); defaultStartRoutCmd.setDataCenter(zoneId);
defaultStartRoutCmd.setPod(_podId); defaultStartRoutCmd.setPod(podId);
defaultStartRoutCmd.setCluster(_clusterId); defaultStartRoutCmd.setCluster(clusterId);
defaultStartRoutCmd.setGuid(_guid); defaultStartRoutCmd.setGuid(guid);
defaultStartRoutCmd.setName(_name); defaultStartRoutCmd.setName(name);
defaultStartRoutCmd.setPrivateIpAddress(_agentIp); defaultStartRoutCmd.setPrivateIpAddress(agentIp);
defaultStartRoutCmd.setStorageIpAddress(_agentIp); defaultStartRoutCmd.setStorageIpAddress(agentIp);
defaultStartRoutCmd.setPool(_clusterGuid); defaultStartRoutCmd.setPool(clusterGuid);
s_logger.debug("Generated StartupRoutingCommand for _agentIp \"" + _agentIp + "\""); s_logger.debug("Generated StartupRoutingCommand for agentIp \"" + agentIp + "\"");
defaultStartRoutCmd.setVersion(this.getClass().getPackage().getImplementationVersion()); defaultStartRoutCmd.setVersion(this.getClass().getPackage().getImplementationVersion());
@ -239,48 +239,48 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
// Assert that host identity is consistent with existing values. // Assert that host identity is consistent with existing values.
if (startCmd == null) { if (startCmd == null) {
final String errMsg = String.format("Host %s (IP %s)" + "did not return a StartupRoutingCommand", _name, _agentIp); final String errMsg = String.format("Host %s (IP %s)" + "did not return a StartupRoutingCommand", name, agentIp);
s_logger.error(errMsg); s_logger.error(errMsg);
// TODO: valid to return null, or should we throw? // TODO: valid to return null, or should we throw?
return null; return null;
} }
if (!startCmd.getDataCenter().equals(defaultStartRoutCmd.getDataCenter())) { if (!startCmd.getDataCenter().equals(defaultStartRoutCmd.getDataCenter())) {
final String errMsg = final String errMsg =
String.format("Host %s (IP %s) changed zone/data center. Was " + defaultStartRoutCmd.getDataCenter() + " NOW its " + startCmd.getDataCenter(), _name, String.format("Host %s (IP %s) changed zone/data center. Was " + defaultStartRoutCmd.getDataCenter() + " NOW its " + startCmd.getDataCenter(), name,
_agentIp); agentIp);
s_logger.error(errMsg); s_logger.error(errMsg);
// TODO: valid to return null, or should we throw? // TODO: valid to return null, or should we throw?
return null; return null;
} }
if (!startCmd.getPod().equals(defaultStartRoutCmd.getPod())) { if (!startCmd.getPod().equals(defaultStartRoutCmd.getPod())) {
final String errMsg = String.format("Host %s (IP %s) changed pod. Was " + defaultStartRoutCmd.getPod() + " NOW its " + startCmd.getPod(), _name, _agentIp); final String errMsg = String.format("Host %s (IP %s) changed pod. Was " + defaultStartRoutCmd.getPod() + " NOW its " + startCmd.getPod(), name, agentIp);
s_logger.error(errMsg); s_logger.error(errMsg);
// TODO: valid to return null, or should we throw? // TODO: valid to return null, or should we throw?
return null; return null;
} }
if (!startCmd.getCluster().equals(defaultStartRoutCmd.getCluster())) { if (!startCmd.getCluster().equals(defaultStartRoutCmd.getCluster())) {
final String errMsg = final String errMsg =
String.format("Host %s (IP %s) changed cluster. Was " + defaultStartRoutCmd.getCluster() + " NOW its " + startCmd.getCluster(), _name, _agentIp); String.format("Host %s (IP %s) changed cluster. Was " + defaultStartRoutCmd.getCluster() + " NOW its " + startCmd.getCluster(), name, agentIp);
s_logger.error(errMsg); s_logger.error(errMsg);
// TODO: valid to return null, or should we throw? // TODO: valid to return null, or should we throw?
return null; return null;
} }
if (!startCmd.getGuid().equals(defaultStartRoutCmd.getGuid())) { if (!startCmd.getGuid().equals(defaultStartRoutCmd.getGuid())) {
final String errMsg = String.format("Host %s (IP %s) changed guid. Was " + defaultStartRoutCmd.getGuid() + " NOW its " + startCmd.getGuid(), _name, _agentIp); final String errMsg = String.format("Host %s (IP %s) changed guid. Was " + defaultStartRoutCmd.getGuid() + " NOW its " + startCmd.getGuid(), name, agentIp);
s_logger.error(errMsg); s_logger.error(errMsg);
// TODO: valid to return null, or should we throw? // TODO: valid to return null, or should we throw?
return null; return null;
} }
if (!startCmd.getPrivateIpAddress().equals(defaultStartRoutCmd.getPrivateIpAddress())) { if (!startCmd.getPrivateIpAddress().equals(defaultStartRoutCmd.getPrivateIpAddress())) {
final String errMsg = final String errMsg =
String.format("Host %s (IP %s) IP address. Was " + defaultStartRoutCmd.getPrivateIpAddress() + " NOW its " + startCmd.getPrivateIpAddress(), _name, String.format("Host %s (IP %s) IP address. Was " + defaultStartRoutCmd.getPrivateIpAddress() + " NOW its " + startCmd.getPrivateIpAddress(), name,
_agentIp); agentIp);
s_logger.error(errMsg); s_logger.error(errMsg);
// TODO: valid to return null, or should we throw? // TODO: valid to return null, or should we throw?
return null; return null;
} }
if (!startCmd.getName().equals(defaultStartRoutCmd.getName())) { if (!startCmd.getName().equals(defaultStartRoutCmd.getName())) {
final String errMsg = String.format("Host %s (IP %s) name. Was " + startCmd.getName() + " NOW its " + defaultStartRoutCmd.getName(), _name, _agentIp); final String errMsg = String.format("Host %s (IP %s) name. Was " + startCmd.getName() + " NOW its " + defaultStartRoutCmd.getName(), name, agentIp);
s_logger.error(errMsg); s_logger.error(errMsg);
// TODO: valid to return null, or should we throw? // TODO: valid to return null, or should we throw?
return null; return null;
@ -300,14 +300,14 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
// TODO: is this assertion required? // TODO: is this assertion required?
if (storePoolCmd == null) { if (storePoolCmd == null) {
final String frmtStr = "Host %s (IP %s) sent incorrect Command, " + "second parameter should be a " + "StartupStorageCommand"; final String frmtStr = "Host %s (IP %s) sent incorrect Command, " + "second parameter should be a " + "StartupStorageCommand";
final String errMsg = String.format(frmtStr, _name, _agentIp); final String errMsg = String.format(frmtStr, name, agentIp);
s_logger.error(errMsg); s_logger.error(errMsg);
// TODO: valid to return null, or should we throw? // TODO: valid to return null, or should we throw?
return null; return null;
} }
s_logger.info("Host " + _name + " (IP " + _agentIp + ") already configured with a storeage pool, details " + s_gson.toJson(startCmds[1])); s_logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details " + s_gson.toJson(startCmds[1]));
} else { } else {
s_logger.info("Host " + _name + " (IP " + _agentIp + ") already configured with a storeage pool, details "); s_logger.info("Host " + name + " (IP " + agentIp + ") already configured with a storeage pool, details ");
} }
return new StartupCommand[] {startCmd, storePoolCmd}; return new StartupCommand[] {startCmd, storePoolCmd};
} }
@ -317,13 +317,13 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
final PingCommand pingCmd = new PingRoutingCommand(getType(), id, getHostVmStateReport()); final PingCommand pingCmd = new PingRoutingCommand(getType(), id, getHostVmStateReport());
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
s_logger.debug("Ping host " + _name + " (IP " + _agentIp + ")"); s_logger.debug("Ping host " + name + " (IP " + agentIp + ")");
} }
final Answer pingAns = executeRequest(pingCmd); final Answer pingAns = executeRequest(pingCmd);
if (pingAns == null || !pingAns.getResult()) { if (pingAns == null || !pingAns.getResult()) {
s_logger.info("Cannot ping host " + _name + " (IP " + _agentIp + "), pingAns (blank means null) is:" + pingAns); s_logger.info("Cannot ping host " + name + " (IP " + agentIp + "), pingAns (blank means null) is:" + pingAns);
return null; return null;
} }
return pingCmd; return pingCmd;
@ -332,7 +332,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
public final ArrayList<Map<String, String>> requestHostVmStateReport() { public final ArrayList<Map<String, String>> requestHostVmStateReport() {
URI agentUri = null; URI agentUri = null;
try { try {
agentUri = new URI("https", null, _agentIp, _port, "/api/HypervResource/" + HOST_VM_STATE_REPORT_COMMAND, null, null); agentUri = new URI("https", null, agentIp, port, "/api/HypervResource/" + HOST_VM_STATE_REPORT_COMMAND, null, null);
} catch (final URISyntaxException e) { } catch (final URISyntaxException e) {
final String errMsg = "Could not generate URI for Hyper-V agent"; final String errMsg = "Could not generate URI for Hyper-V agent";
s_logger.error(errMsg, e); s_logger.error(errMsg, e);
@ -372,7 +372,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
for (final Map<String, String> vmMap : vmList) { for (final Map<String, String> vmMap : vmList) {
final String name = (String)vmMap.keySet().toArray()[0]; final String name = (String)vmMap.keySet().toArray()[0];
vmStates.put(name, new HostVmStateReportEntry(PowerState.valueOf(vmMap.get(name)), _guid)); vmStates.put(name, new HostVmStateReportEntry(PowerState.valueOf(vmMap.get(name)), guid));
} }
return vmStates; return vmStates;
} }
@ -388,7 +388,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
try { try {
final String cmdName = StartupCommand.class.getName(); final String cmdName = StartupCommand.class.getName();
agentUri = agentUri =
new URI("https", null, _agentIp, _port, new URI("https", null, agentIp, port,
"/api/HypervResource/" + cmdName, null, null); "/api/HypervResource/" + cmdName, null, null);
} catch (final URISyntaxException e) { } catch (final URISyntaxException e) {
// TODO add proper logging // TODO add proper logging
@ -427,7 +427,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
try { try {
final String cmdName = cmd.getClass().getName(); final String cmdName = cmd.getClass().getName();
agentUri = agentUri =
new URI("https", null, _agentIp, _port, new URI("https", null, agentIp, port,
"/api/HypervResource/" + cmdName, null, null); "/api/HypervResource/" + cmdName, null, null);
} catch (final URISyntaxException e) { } catch (final URISyntaxException e) {
// TODO add proper logging // TODO add proper logging
@ -436,7 +436,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
return null; return null;
} }
if (cmd instanceof NetworkElementCommand) { if (cmd instanceof NetworkElementCommand) {
return _vrResource.executeRequest((NetworkElementCommand)cmd); return vrResource.executeRequest((NetworkElementCommand)cmd);
}if (clazz == CheckSshCommand.class) { }if (clazz == CheckSshCommand.class) {
answer = execute((CheckSshCommand)cmd); answer = execute((CheckSshCommand)cmd);
} else if (cmd instanceof NetworkUsageCommand) { } else if (cmd instanceof NetworkUsageCommand) {
@ -455,7 +455,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
final VirtualMachineTO vmSpec = ((StartCommand)cmd).getVirtualMachine(); final VirtualMachineTO vmSpec = ((StartCommand)cmd).getVirtualMachine();
if (vmSpec.getType() != VirtualMachine.Type.User) { if (vmSpec.getType() != VirtualMachine.Type.User) {
if (s_hypervMgr != null) { if (s_hypervMgr != null) {
final String secondary = s_hypervMgr.prepareSecondaryStorageStore(Long.parseLong(_zoneId)); final String secondary = s_hypervMgr.prepareSecondaryStorageStore(Long.parseLong(zoneId));
if (secondary != null) { if (secondary != null) {
((StartCommand)cmd).setSecondaryStorage(secondary); ((StartCommand)cmd).setSecondaryStorage(secondary);
} }
@ -487,7 +487,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
try { try {
final String cmdName = cmd.getClass().getName(); final String cmdName = cmd.getClass().getName();
agentUri = agentUri =
new URI("https", null, _agentIp, _port, new URI("https", null, agentIp, port,
"/api/HypervResource/" + cmdName, null, null); "/api/HypervResource/" + cmdName, null, null);
} catch (final URISyntaxException e) { } catch (final URISyntaxException e) {
final String errMsg = "Could not generate URI for Hyper-V agent"; final String errMsg = "Could not generate URI for Hyper-V agent";
@ -1803,7 +1803,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
try { try {
final String cmdName = GetVmConfigCommand.class.getName(); final String cmdName = GetVmConfigCommand.class.getName();
agentUri = agentUri =
new URI("https", null, _agentIp, _port, new URI("https", null, agentIp, port,
"/api/HypervResource/" + cmdName, null, null); "/api/HypervResource/" + cmdName, null, null);
} catch (final URISyntaxException e) { } catch (final URISyntaxException e) {
final String errMsg = "Could not generate URI for Hyper-V agent"; final String errMsg = "Could not generate URI for Hyper-V agent";
@ -1836,7 +1836,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
try { try {
final String cmdName = GetVmConfigCommand.class.getName(); final String cmdName = GetVmConfigCommand.class.getName();
agentUri = agentUri =
new URI("https", null, _agentIp, _port, new URI("https", null, agentIp, port,
"/api/HypervResource/" + cmdName, null, null); "/api/HypervResource/" + cmdName, null, null);
} catch (final URISyntaxException e) { } catch (final URISyntaxException e) {
final String errMsg = "Could not generate URI for Hyper-V agent"; final String errMsg = "Could not generate URI for Hyper-V agent";
@ -1865,7 +1865,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
try { try {
final String cmdName = ModifyVmNicConfigCommand.class.getName(); final String cmdName = ModifyVmNicConfigCommand.class.getName();
agentUri = agentUri =
new URI("https", null, _agentIp, _port, new URI("https", null, agentIp, port,
"/api/HypervResource/" + cmdName, null, null); "/api/HypervResource/" + cmdName, null, null);
} catch (final URISyntaxException e) { } catch (final URISyntaxException e) {
final String errMsg = "Could not generate URI for Hyper-V agent"; final String errMsg = "Could not generate URI for Hyper-V agent";
@ -1886,7 +1886,7 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
try { try {
final String cmdName = ModifyVmNicConfigCommand.class.getName(); final String cmdName = ModifyVmNicConfigCommand.class.getName();
agentUri = agentUri =
new URI("https", null, _agentIp, _port, new URI("https", null, agentIp, port,
"/api/HypervResource/" + cmdName, null, null); "/api/HypervResource/" + cmdName, null, null);
} catch (final URISyntaxException e) { } catch (final URISyntaxException e) {
final String errMsg = "Could not generate URI for Hyper-V agent"; final String errMsg = "Could not generate URI for Hyper-V agent";
@ -2298,22 +2298,22 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
/* todo: update, make consistent with the xen server equivalent. */ /* todo: update, make consistent with the xen server equivalent. */
if (params != null) { if (params != null) {
_guid = (String)params.get("guid"); guid = (String)params.get("guid");
_zoneId = (String)params.get("zone"); zoneId = (String)params.get("zone");
_podId = (String)params.get("pod"); podId = (String)params.get("pod");
_clusterId = (String)params.get("cluster"); clusterId = (String)params.get("cluster");
_agentIp = (String)params.get("ipaddress"); // was agentIp agentIp = (String)params.get("ipaddress"); // was agentIp
_name = name; this.name = name;
_clusterGuid = (String)params.get("cluster.guid"); clusterGuid = (String)params.get("cluster.guid");
_username = (String)params.get("url"); username = (String)params.get("url");
_password = (String)params.get("password"); password = (String)params.get("password");
_username = (String)params.get("username"); username = (String)params.get("username");
_configureCalled = true; configureCalled = true;
} }
_vrResource = new VirtualRoutingResource(this); vrResource = new VirtualRoutingResource(this);
if (!_vrResource.configure(name, new HashMap<String, Object>())) { if (!vrResource.configure(name, new HashMap<String, Object>())) {
throw new ConfigurationException("Unable to configure VirtualRoutingResource"); throw new ConfigurationException("Unable to configure VirtualRoutingResource");
} }
return true; return true;
@ -2349,11 +2349,11 @@ public class HypervDirectConnectResource extends ServerResourceBase implements S
protected String connect(final String vmName, final String ipAddress, final int port) { protected String connect(final String vmName, final String ipAddress, final int port) {
final long startTick = System.currentTimeMillis(); final long startTick = System.currentTimeMillis();
// wait until we have at least been waiting for _ops_timeout time or // wait until we have at least been waiting for ops_timeout time or
// at least have tried _retry times, this is to coordinate with system // at least have tried retry times, this is to coordinate with system
// VM patching/rebooting time that may need // VM patching/rebooting time that may need
int retry = _retry; int retry = this.retry;
while (System.currentTimeMillis() - startTick <= _opsTimeout || --retry > 0) { while (System.currentTimeMillis() - startTick <= opsTimeout || --retry > 0) {
s_logger.info("Trying to connect to " + ipAddress); s_logger.info("Trying to connect to " + ipAddress);
try (SocketChannel sch = SocketChannel.open();) { try (SocketChannel sch = SocketChannel.open();) {
sch.configureBlocking(true); sch.configureBlocking(true);

View File

@ -269,7 +269,7 @@ public class LibvirtComputingResourceTest {
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
libvirtComputingResourceSpy._qemuSocketsPath = new File("/var/run/qemu"); libvirtComputingResourceSpy.qemuSocketsPath = new File("/var/run/qemu");
libvirtComputingResourceSpy.parser = parserMock; libvirtComputingResourceSpy.parser = parserMock;
LibvirtComputingResource.s_logger = loggerMock; LibvirtComputingResource.s_logger = loggerMock;
} }
@ -466,8 +466,8 @@ public class LibvirtComputingResourceTest {
@Test @Test
public void testConfigureGuestAndSystemVMToUseKVM() { public void testConfigureGuestAndSystemVMToUseKVM() {
VirtualMachineTO to = createDefaultVM(false); VirtualMachineTO to = createDefaultVM(false);
libvirtComputingResourceSpy._hypervisorLibvirtVersion = 100; libvirtComputingResourceSpy.hypervisorLibvirtVersion = 100;
libvirtComputingResourceSpy._hypervisorQemuVersion = 10; libvirtComputingResourceSpy.hypervisorQemuVersion = 10;
LibvirtVMDef vm = new LibvirtVMDef(); LibvirtVMDef vm = new LibvirtVMDef();
GuestDef guestFromSpec = libvirtComputingResourceSpy.createGuestFromSpec(to, vm, to.getUuid(), null); GuestDef guestFromSpec = libvirtComputingResourceSpy.createGuestFromSpec(to, vm, to.getUuid(), null);
@ -478,7 +478,7 @@ public class LibvirtComputingResourceTest {
@Test @Test
public void testConfigureGuestAndUserVMToUseLXC() { public void testConfigureGuestAndUserVMToUseLXC() {
VirtualMachineTO to = createDefaultVM(false); VirtualMachineTO to = createDefaultVM(false);
libvirtComputingResourceSpy._hypervisorType = HypervisorType.LXC; libvirtComputingResourceSpy.hypervisorType = HypervisorType.LXC;
LibvirtVMDef vm = new LibvirtVMDef(); LibvirtVMDef vm = new LibvirtVMDef();
GuestDef guestFromSpec = libvirtComputingResourceSpy.createGuestFromSpec(to, vm, to.getUuid(), null); GuestDef guestFromSpec = libvirtComputingResourceSpy.createGuestFromSpec(to, vm, to.getUuid(), null);
@ -545,7 +545,7 @@ public class LibvirtComputingResourceTest {
@Test @Test
public void testCreateClockDefKvmclock() { public void testCreateClockDefKvmclock() {
VirtualMachineTO to = createDefaultVM(false); VirtualMachineTO to = createDefaultVM(false);
libvirtComputingResourceSpy._hypervisorLibvirtVersion = 9020; libvirtComputingResourceSpy.hypervisorLibvirtVersion = 9020;
ClockDef clockDef = libvirtComputingResourceSpy.createClockDef(to); ClockDef clockDef = libvirtComputingResourceSpy.createClockDef(to);
Document domainDoc = parse(clockDef.toString()); Document domainDoc = parse(clockDef.toString());
@ -652,8 +652,8 @@ public class LibvirtComputingResourceTest {
@Test @Test
public void testCreateVideoDef() { public void testCreateVideoDef() {
VirtualMachineTO to = createDefaultVM(false); VirtualMachineTO to = createDefaultVM(false);
libvirtComputingResourceSpy._videoRam = 200; libvirtComputingResourceSpy.videoRam = 200;
libvirtComputingResourceSpy._videoHw = "vGPU"; libvirtComputingResourceSpy.videoHw = "vGPU";
VideoDef videoDef = libvirtComputingResourceSpy.createVideoDef(to); VideoDef videoDef = libvirtComputingResourceSpy.createVideoDef(to);
Document domainDoc = parse(videoDef.toString()); Document domainDoc = parse(videoDef.toString());
@ -5665,7 +5665,7 @@ public class LibvirtComputingResourceTest {
VirtualMachineTO vmTo = Mockito.mock(VirtualMachineTO.class); VirtualMachineTO vmTo = Mockito.mock(VirtualMachineTO.class);
Mockito.when(vmTo.getType()).thenReturn(Type.User); Mockito.when(vmTo.getType()).thenReturn(Type.User);
LibvirtComputingResource libvirtComputingResource = new LibvirtComputingResource(); LibvirtComputingResource libvirtComputingResource = new LibvirtComputingResource();
libvirtComputingResource._noMemBalloon = true; libvirtComputingResource.noMemBalloon = true;
long maxMemory = 2048; long maxMemory = 2048;
long currentMemory = libvirtComputingResource.getCurrentMemAccordingToMemBallooning(vmTo, maxMemory); long currentMemory = libvirtComputingResource.getCurrentMemAccordingToMemBallooning(vmTo, maxMemory);
@ -5676,7 +5676,7 @@ public class LibvirtComputingResourceTest {
@Test @Test
public void validateGetCurrentMemAccordingToMemBallooningWithtMemBalooning(){ public void validateGetCurrentMemAccordingToMemBallooningWithtMemBalooning(){
LibvirtComputingResource libvirtComputingResource = new LibvirtComputingResource(); LibvirtComputingResource libvirtComputingResource = new LibvirtComputingResource();
libvirtComputingResource._noMemBalloon = false; libvirtComputingResource.noMemBalloon = false;
long maxMemory = 2048; long maxMemory = 2048;
long minMemory = ByteScaleUtils.mebibytesToBytes(64); long minMemory = ByteScaleUtils.mebibytesToBytes(64);
@ -5893,8 +5893,8 @@ public class LibvirtComputingResourceTest {
Assert.assertEquals("cloudbr15", keys.get(0)); Assert.assertEquals("cloudbr15", keys.get(0));
Assert.assertEquals("cloudbr28", keys.get(1)); Assert.assertEquals("cloudbr28", keys.get(1));
Assert.assertEquals("cloudbr15", libvirtComputingResourceSpy._privBridgeName); Assert.assertEquals("cloudbr15", libvirtComputingResourceSpy.privBridgeName);
Assert.assertEquals("cloudbr28", libvirtComputingResourceSpy._publicBridgeName); Assert.assertEquals("cloudbr28", libvirtComputingResourceSpy.publicBridgeName);
Assert.assertEquals(networkInterfaceMock1, libvirtComputingResourceSpy.getPrivateNic()); Assert.assertEquals(networkInterfaceMock1, libvirtComputingResourceSpy.getPrivateNic());
Assert.assertEquals(networkInterfaceMock2, libvirtComputingResourceSpy.getPublicNic()); Assert.assertEquals(networkInterfaceMock2, libvirtComputingResourceSpy.getPublicNic());

View File

@ -121,11 +121,11 @@ public class LibvirtVifDriverTest {
// map to the default vif driver for the bridge type // map to the default vif driver for the bridge type
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
res._bridgeType = BridgeType.NATIVE; res.bridgeType = BridgeType.NATIVE;
configure(params); configure(params);
checkAllSame(bridgeVifDriver); checkAllSame(bridgeVifDriver);
res._bridgeType = BridgeType.OPENVSWITCH; res.bridgeType = BridgeType.OPENVSWITCH;
configure(params); configure(params);
checkAllSame(ovsVifDriver); checkAllSame(ovsVifDriver);
} }
@ -141,11 +141,11 @@ public class LibvirtVifDriverTest {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
// Switch res' bridge type for test purposes // Switch res' bridge type for test purposes
res._bridgeType = BridgeType.NATIVE; res.bridgeType = BridgeType.NATIVE;
configure(params); configure(params);
checkAllSame(bridgeVifDriver); checkAllSame(bridgeVifDriver);
res._bridgeType = BridgeType.OPENVSWITCH; res.bridgeType = BridgeType.OPENVSWITCH;
configure(params); configure(params);
checkAllSame(ovsVifDriver); checkAllSame(ovsVifDriver);
@ -167,11 +167,11 @@ public class LibvirtVifDriverTest {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
// Switch res' bridge type for test purposes // Switch res' bridge type for test purposes
res._bridgeType = BridgeType.NATIVE; res.bridgeType = BridgeType.NATIVE;
configure(params); configure(params);
checkAllSame(ovsVifDriver); checkAllSame(ovsVifDriver);
res._bridgeType = BridgeType.OPENVSWITCH; res.bridgeType = BridgeType.OPENVSWITCH;
configure(params); configure(params);
checkAllSame(bridgeVifDriver); checkAllSame(bridgeVifDriver);
@ -186,7 +186,7 @@ public class LibvirtVifDriverTest {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put(LibVirtVifDriver + "." + "Public", FakeVifDriverClassName); params.put(LibVirtVifDriver + "." + "Public", FakeVifDriverClassName);
params.put(LibVirtVifDriver + "." + "Guest", LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS_NAME); params.put(LibVirtVifDriver + "." + "Guest", LibvirtComputingResource.DEFAULT_OVS_VIF_DRIVER_CLASS_NAME);
res._bridgeType = BridgeType.NATIVE; res.bridgeType = BridgeType.NATIVE;
configure(params); configure(params);
// Initially, set all traffic types to use default // Initially, set all traffic types to use default
@ -204,7 +204,7 @@ public class LibvirtVifDriverTest {
public void testBadTrafficType() throws ConfigurationException { public void testBadTrafficType() throws ConfigurationException {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put(LibVirtVifDriver + "." + "NonExistentTrafficType", FakeVifDriverClassName); params.put(LibVirtVifDriver + "." + "NonExistentTrafficType", FakeVifDriverClassName);
res._bridgeType = BridgeType.NATIVE; res.bridgeType = BridgeType.NATIVE;
configure(params); configure(params);
// Set all traffic types to use default, because bad traffic type should be ignored // Set all traffic types to use default, because bad traffic type should be ignored
@ -219,7 +219,7 @@ public class LibvirtVifDriverTest {
public void testEmptyTrafficType() throws ConfigurationException { public void testEmptyTrafficType() throws ConfigurationException {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put(LibVirtVifDriver + ".", FakeVifDriverClassName); params.put(LibVirtVifDriver + ".", FakeVifDriverClassName);
res._bridgeType = BridgeType.NATIVE; res.bridgeType = BridgeType.NATIVE;
configure(params); configure(params);
// Set all traffic types to use default, because bad traffic type should be ignored // Set all traffic types to use default, because bad traffic type should be ignored
@ -234,7 +234,7 @@ public class LibvirtVifDriverTest {
public void testBadVifDriverClassName() throws ConfigurationException { public void testBadVifDriverClassName() throws ConfigurationException {
Map<String, Object> params = new HashMap<String, Object>(); Map<String, Object> params = new HashMap<String, Object>();
params.put(LibVirtVifDriver + "." + "Public", NonExistentVifDriverClassName); params.put(LibVirtVifDriver + "." + "Public", NonExistentVifDriverClassName);
res._bridgeType = BridgeType.NATIVE; res.bridgeType = BridgeType.NATIVE;
configure(params); configure(params);
} }
} }

View File

@ -211,7 +211,7 @@ public class LibvirtNetworkElementCommandWrapperTest {
+ "</domain>\n"; + "</domain>\n";
private LibvirtComputingResource res; private LibvirtComputingResource res;
private final Domain _domain = mock(Domain.class); private final Domain domain = mock(Domain.class);
final String memInfo = "MemTotal: 5830236 kB\n" + final String memInfo = "MemTotal: 5830236 kB\n" +
"MemFree: 156752 kB\n" + "MemFree: 156752 kB\n" +
@ -225,10 +225,10 @@ public class LibvirtNetworkElementCommandWrapperTest {
// Use a spy because we only want to override getVifDriverClass // Use a spy because we only want to override getVifDriverClass
LibvirtComputingResource resReal = new LibvirtComputingResource() { LibvirtComputingResource resReal = new LibvirtComputingResource() {
{ {
_linkLocalBridgeName = "cloud0"; linkLocalBridgeName = "cloud0";
_guestBridgeName = "guestbr"; guestBridgeName = "guestbr";
_publicBridgeName = "publicbr"; publicBridgeName = "publicbr";
_privBridgeName = "mgmtbr"; privBridgeName = "mgmtbr";
} }
}; };
@ -237,8 +237,8 @@ public class LibvirtNetworkElementCommandWrapperTest {
Connect conn = mock(Connect.class); Connect conn = mock(Connect.class);
LibvirtUtilitiesHelper helper = mock(LibvirtUtilitiesHelper.class); LibvirtUtilitiesHelper helper = mock(LibvirtUtilitiesHelper.class);
when(_domain.getXMLDesc(0)).thenReturn(fullfile); when(domain.getXMLDesc(0)).thenReturn(fullfile);
when(conn.domainLookupByName(nullable(String.class))).thenReturn(_domain); when(conn.domainLookupByName(nullable(String.class))).thenReturn(domain);
when(helper.getConnectionByVmName(nullable(String.class))).thenReturn(conn); when(helper.getConnectionByVmName(nullable(String.class))).thenReturn(conn);
doReturn(helper).when(res).getLibvirtUtilitiesHelper(); doReturn(helper).when(res).getLibvirtUtilitiesHelper();