Skip to content

Commit

Permalink
Merge branch 'add-nics-to-virtual-machine' into 'master'
Browse files Browse the repository at this point in the history
Add network interfaces in virtual machine API response

See merge request !12
  • Loading branch information
tomskikh committed Sep 27, 2018
2 parents b5c871d + 5952a7a commit b5e6c32
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ trait TestEntities {
val zoneDao = new ZoneDao(executor, mapper)
val zoneFindRequest = new ZoneFindRequest()
zoneFindRequest.withAvailableFlag(true)
zoneFindRequest.addParameter("networktype", "Advanced")

zoneDao.find(zoneFindRequest).head.id
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ import java.util.UUID

import br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackRequest
import com.bwsw.cloudstack.entities.TestEntities
import com.bwsw.cloudstack.entities.requests.Constants
import com.bwsw.cloudstack.entities.requests.Constants.ParameterKeys
import com.bwsw.cloudstack.entities.requests.account.AccountFindRequest
import com.bwsw.cloudstack.entities.responses.account.AccountFindResponse
import com.bwsw.cloudstack.entities.responses.vm.{VirtualMachine, VirtualMachineCreateResponse, VirtualMachineFindResponse}
import com.bwsw.cloudstack.entities.util.requests.IntegrationTestConstants.ParameterValues
import org.scalatest.FlatSpec
import org.scalatest.{FlatSpec, Matchers}

class VmCreateRequestIntegrationTestSuite extends FlatSpec with TestEntities {
val serviceOfferingId = retrievedServiceOfferingId
val templateId = retrievedTemplateId
val zoneId = retrievedZoneId
class VmCreateRequestIntegrationTestSuite
extends FlatSpec
with TestEntities
with Matchers {

val serviceOfferingId: UUID = retrievedServiceOfferingId
val templateId: UUID = retrievedTemplateId
val zoneId: UUID = retrievedZoneId

it should "create a vm using a request which contains only required parameters" in {
val vmCreateRequest = new VmCreateRequest(VmCreateRequest.Settings(serviceOfferingId, templateId, zoneId))
Expand Down Expand Up @@ -60,9 +66,28 @@ class VmCreateRequestIntegrationTestSuite extends FlatSpec with TestEntities {

val actualVm = mapper.deserialize[VirtualMachineFindResponse](executor.executeRequest(vmFindRequest.getRequest))
.entityList.entities.get.head
val expectedVm = VirtualMachine(vmId, zoneId, templateId, serviceOfferingId, accountName, domainId)
val expectedVm = VirtualMachine(vmId, zoneId, templateId, serviceOfferingId, accountName, domainId, Seq.empty)

actualVm.copy(networkInterfaces = Seq.empty) shouldBe expectedVm
actualVm.networkInterfaces.size should be > 0

val networkInterface = actualVm.networkInterfaces.head

val addIpRequest = new ApacheCloudStackRequest("addIpToNic")
.addParameter("nicid", networkInterface.id)
.addParameter(ParameterKeys.RESPONSE, Constants.ParameterValues.JSON)

executor.executeRequest(addIpRequest)

val actualVmWithSecondaryIps = mapper.deserialize[VirtualMachineFindResponse](executor.executeRequest(vmFindRequest.getRequest))
.entityList.entities.get.head

assert(actualVm == expectedVm)
actualVmWithSecondaryIps.networkInterfaces.map(_.id) should contain(networkInterface.id)
val networkInterfaceWithSecondaryIps = actualVmWithSecondaryIps.networkInterfaces.find(_.id == networkInterface.id).get
networkInterfaceWithSecondaryIps.secondaryIps.length should be >= 1
networkInterfaceWithSecondaryIps.secondaryIps.foreach { secondaryIp =>
Some(secondaryIp.id) shouldBe defined
}
}

it should "create a vm using a request which contains only required parameters and a parameter with incorrect key" in {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.bwsw.cloudstack.entities.responses.vm

import java.util.UUID

import com.bwsw.cloudstack.entities.responses.common.Entity
import com.fasterxml.jackson.annotation.JsonProperty

final case class NetworkInterface(id: UUID,
@JsonProperty("secondaryip") secondaryIps: Seq[SecondaryIp])
extends Entity
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.bwsw.cloudstack.entities.responses.vm

import java.util.UUID

import com.bwsw.cloudstack.entities.responses.common.Entity

final case class SecondaryIp(id: UUID) extends Entity
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ case class VirtualMachine(id: UUID,
@JsonProperty("templateid") templateId: UUID,
@JsonProperty("serviceofferingid") serviceOfferingId: UUID,
@JsonProperty("account") accountName: String,
@JsonProperty("domainid") domainId: UUID) extends Entity
@JsonProperty("domainid") domainId: UUID,
@JsonProperty("nic") networkInterfaces: Seq[NetworkInterface])
extends Entity
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import java.util.UUID
import com.bwsw.cloudstack.KeyAuthenticationClientCreator
import com.bwsw.cloudstack.entities.Executor
import com.bwsw.cloudstack.entities.common.JsonMapper
import com.bwsw.cloudstack.entities.responses.account.{Account, AccountFindResponse, AccountList}
import com.bwsw.cloudstack.entities.responses.user.{User, UserFindResponse, UserList}
import com.bwsw.cloudstack.entities.responses.account.Account
import com.bwsw.cloudstack.entities.responses.user.User
import com.bwsw.cloudstack.entities.responses.vm.VirtualMachine

trait TestData {
Expand Down Expand Up @@ -88,6 +88,7 @@ trait TestData {
templateId = UUID.randomUUID(),
serviceOfferingId = UUID.randomUUID(),
accountName = accountName,
domainId = domainId
domainId = domainId,
networkInterfaces = Seq.empty
)
}

0 comments on commit b5e6c32

Please sign in to comment.