Skip to content

Commit

Permalink
[CE-153] [CE-154] Enhance error message in agent
Browse files Browse the repository at this point in the history
Throw more user friendly message.
Add more time for waiting the docker instance to up.

Change-Id: I6d3311c8bd25c22eec290d4551e9c6ef88c65491
Signed-off-by: hainingzhang <[email protected]>
  • Loading branch information
hainingzhang committed Oct 19, 2017
1 parent 4420125 commit fdfdef6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 43 deletions.
74 changes: 51 additions & 23 deletions src/agent/vsphere/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,31 @@ def create(self, vcip, username, pwd, port, params):
:return:
"""
# Init connection
si = initializesi(vcip, username, pwd, port)
connection = si.RetrieveContent()
vc_resources = params.get(VCENTER)
try:
si = initializesi(vcip, username, pwd, port)
connection = si.RetrieveContent()
vc_resources = params.get(VCENTER)

except Exception as e:
error_msg = (
"Cannot complete login due to"
" an incorrect user name or password."
)
raise Exception(error_msg)

# Check cluster
cluster = check_vc_resource(connection,
[vim.ClusterComputeResource],
vc_resources[VC_CLUSTER])
if cluster is None:
logger.error("The Cluster: {} does not exist,"
"or exception is raised."
.format(vc_resources[VC_CLUSTER]))
return False
error_msg = (
"The Cluster: {} does not exist"
" or exception is raised."
).format(vc_resources[VC_CLUSTER])

logger.error(error_msg)
raise Exception(error_msg)

else:
vc_resources[VC_CLUSTER] = cluster

Expand All @@ -60,10 +72,14 @@ def create(self, vcip, username, pwd, port, params):
[vim.Datacenter],
vc_resources[VC_DATACENTER])
if datacenter is None:
logger.error("The DataCenter: {} does not exist,"
"or exception is raised."
.format(vc_resources[VC_DATACENTER]))
return False
error_msg = (
"The DataCenter: {} does not exist"
" or exception is raised."
).format(vc_resources[VC_DATACENTER])

logger.error(error_msg)
raise Exception(error_msg)

else:
vc_resources[VC_DATACENTER] = datacenter

Expand All @@ -72,10 +88,14 @@ def create(self, vcip, username, pwd, port, params):
[vim.Datastore],
vc_resources[VC_DATASTORE])
if datastore is None:
logger.error("The Datastore: {} does not exist,"
"or exception is raised."
.format(vc_resources[VC_DATASTORE]))
return False
error_msg = (
"The Datastore: {} does not exist"
" or exception is raised."
).format(vc_resources[VC_DATASTORE])

logger.error(error_msg)
raise Exception(error_msg)

else:
vc_resources[VC_DATASTORE] = datastore

Expand All @@ -84,10 +104,14 @@ def create(self, vcip, username, pwd, port, params):
[vim.VirtualMachine],
vc_resources[TEMPLATE])
if template is None:
logger.error("The template: {} does not exist,"
"or exception is raised."
.format(vc_resources[TEMPLATE]))
return False
error_msg = (
"The template: {} does not exist"
" or exception is raised."
).format(vc_resources[TEMPLATE])

logger.error(error_msg)
raise Exception(error_msg)

else:
vc_resources[TEMPLATE] = template

Expand All @@ -96,10 +120,14 @@ def create(self, vcip, username, pwd, port, params):
[vim.Network],
vc_resources[NETWORK])
if network is None:
logger.error("The network: {} does not exist,"
"or exception is raised."
.format(vc_resources[NETWORK]))
return False
error_msg = (
"The network: {} does not exist"
" or exception is raised."
).format(vc_resources[NETWORK])

logger.error(error_msg)
raise Exception(error_msg)

else:
vc_resources[NETWORK] = network

Expand Down
36 changes: 19 additions & 17 deletions src/agent/vsphere/host_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ def setup_vm(connection, params):
network = vc.get(utils.NETWORK)
destfolder = datacenter.vmFolder

# create connection

vmconf = vim.vm.ConfigSpec(numCPUs=vmcpunum,
memoryMB=vmmem * 1024)
# nic
Expand Down Expand Up @@ -186,16 +184,16 @@ def setup_vm(connection, params):
clonespec.powerOn = True

host = {
'vm_uuid': '',
'vm_ip': vmip,
'vm_netmask': vmnetmask,
'vm_dns': vmdns,
'vm_gateway': vmgateway,
'vm_cpunum': vmcpunum,
'vm_mem': vmmem,
'vc_cluster': cluster.name,
'vc_datastore': datastore.name,
'vc_datacenter': datacenter.name,
utils.VMUUID: '',
utils.VMIP: vmip,
utils.VMNETMASK: vmnetmask,
utils.VMDNS: vmdns,
utils.VMGATEWAY: vmgateway,
utils.VMCPU: vmcpunum,
utils.VMMEMORY: vmmem,
utils.VC_CLUSTER: cluster.name,
utils.VC_DATASTORE: datastore.name,
utils.VC_DATACENTER: datacenter.name,
}
try:
task = template.Clone(folder=destfolder, name=vmname, spec=clonespec)
Expand All @@ -204,7 +202,7 @@ def setup_vm(connection, params):
vm = check_object(connection, [vim.VirtualMachine], vmname)
workerapi = "tcp://" + vmip + ":2375"
uuid = vm.summary.config.uuid
host.update({"vm_uuid": uuid})
host.update({utils.VMUUID: uuid})
if check_isport_open(vmip, utils.WORKER_API_PORT,
utils.DEFAULT_TIMEOUT):
if setup_container_host(utils.WORKER_TYPE_DOCKER,
Expand All @@ -214,11 +212,15 @@ def setup_vm(connection, params):
else:
host["status"] = 'error'
logger.error("Failed to setup container host")
col.find_one_and_update({"name": vmname}, {"$set": host})
# Should be safe to delete vm though VsphereHost layer.
else:
host["status"] = 'error'
logger.error("Failed to ping docker daemon:{}:{}"
.format(vmip, "2375"))
col.find_one_and_update({utils.VMNAME: vmname}, {"$set": host})
# Should be safe to delete vm though VsphereHost layer.
except Exception as e:
logger.error(e)
col.delete_one({"name": vmname})
col.delete_one({utils.VMNAME: vmname})
return


Expand Down Expand Up @@ -305,7 +307,7 @@ def check_vmstatus(vcip, username, pwd, port, uuid):
return False


def check_isport_open(vmip, vmport, timeout=30):
def check_isport_open(vmip, vmport, timeout=300):
"""
Check whether the vmport is ready.
:param vmip:
Expand Down
2 changes: 1 addition & 1 deletion src/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CONSENSUS_PLUGINS_FABRIC_V1, CONSENSUS_PLUGIN_SOLO, \
CONSENSUS_MODES, CONSENSUS_TYPES_FABRIC_V1, \
WORKER_TYPES, WORKER_TYPE_DOCKER, WORKER_TYPE_SWARM, WORKER_TYPE_K8S, \
CLUSTER_PORT_START, CLUSTER_PORT_STEP, \
WORKER_TYPE_VSPHERE, CLUSTER_PORT_START, CLUSTER_PORT_STEP, \
NETWORK_SIZE_FABRIC_PRE_V1, NETWORK_SIZE_FABRIC_V1, \
CLUSTER_NETWORK, \
CLUSTER_LOG_TYPES, CLUSTER_LOG_LEVEL, \
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
VM_DEFAULT_HOSTNAME = "Cello"
VMMEMORY = 'memory'
VMCPU = 'vcpus'
VMNAME = 'name'
VMNAME = 'vmname'
VMIP = 'ip'
VMNETMASK = 'netmask'
VMDNS = 'dns'
Expand All @@ -105,7 +105,7 @@
VC_DEFAULT_PORT = 443
VCTHREAD_NAME = "setupvm"
WORKER_API_PORT = 2375
DEFAULT_TIMEOUT = 4
DEFAULT_TIMEOUT = 300


def json_decode(jsonstr):
Expand Down

0 comments on commit fdfdef6

Please sign in to comment.