Open mattbowes opened 4 years ago
Any updates?
I believe that these methods do work if the instance exists. Are you able to throw in a it { should exist }
assertion before calling those?
We use these in the integration tests which currently pass
I believe that these methods do work if the instance exists. Are you able to throw in a
it { should exist }
assertion before calling those?
yes. I did.
this_instance = google_compute_instance(project: gcp_project_id, zone: zone, name: vm_name)
describe this_instance do
it { should exist }
# wait up to 15 minutes if the Compute Engine instance is not yet ready
its('status', retry: 45, retry_wait: 20){should eq 'RUNNING'}
its('machine_type') { should match machine_type }
##[cut here]
### Below check doesn't work
its('first_network_interface_nat_ip_exists'){ should be false }
We able to test that a GCP compute instance has a single public IP address, but we can't test that a GCP compute instance doesn't have a single public IP address
that step:
its('first_network_interface_nat_ip_exists'){ should be false }
please find the output when we have an external IP address:
× Instance win-toolbox-vm-01 first_network_interface_nat_ip_exists is expected to equal false
expected false
got true
please find the output when instance doesn't have an external IP address:
× Instance win-toolbox-vm-01 first_network_interface_nat_ip_exists
undefined method `[]' for nil:NilClass
please find related .rb code here: https://github.com/inspec/inspec-gcp/blob/master/libraries/google_compute_instance.rb
The reason is:
def parse
@network_interfaces = GoogleInSpec::Compute::Property::InstanceNetworkInterfacesArray.parse(@fetched['networkInterfaces'], to_s)
[cut here]
def first_network_interface_nat_ip_exists
!@network_interfaces[0].access_configs[0].nat_ip.nil?
end
According to Google API: access_configs : An array of configurations for this interface. Currently, only one access config, ONE_TO_ONE_NAT, is supported. If there are no accessConfigs specified, then this instance will have no external internet access.
So with first_network_interface_nat_ip_exists we cannot check that first_network_interface_nat_ip_exists doesn't; exist.
So my question here: how can we check that VM instance doesn't have external IP? This is the most common variant to check.
Loop through the network_interfaces
array and check that access_configs
is always empty?
this_instance.network_interfaces.each do |network_interface|
describe network_interface do
its('size') { should cmp 0 }
end
end
Loop through the
network_interfaces
array and check thataccess_configs
is always empty?
It doesn't work, got following:
× Instance win-toolbox-vm-01 InstanceNetworkInterfaces size
undefined method `size' for #<#<Class:0x00007fffd0b5dee8>::GoogleInSpec::Compute::Property::InstanceNetworkInterfaces:0x00007fa0b3affb80>
Errr, try its('count')
I mixed up my ruby methods
Errr, try
its('count')
Unfortunately still the same issue
× Instance win-toolbox-vm-01 InstanceNetworkInterfaces count
undefined method `count' for #<#<Class:0x00007fffc6f5fbe0>::GoogleInSpec::Compute::Property::InstanceNetworkInterfaces:0x00007fffc792cee8>
from the
google_compute_instance
examplesreturns
Tried on profile version
1.0-1.5
Describe the problem
Possible Solution