Comments (5)
OK, I've create a new issue #201 and pull request #202.
Respectfully, I disagree on wontfix for this issue. I agree, as you said in your comment on #166, that the spec must return a single instance. In my code example:
describe ec2('My Server') do
it { should be_running }
end
... clearly, if I have multiple instances with Name = 'My Server', this spec doesn't make any sense. But it also doesn't make sense for this to fail when there is a terminated instance with that Name. This issue breaks my workflow. And there are also many people like @ajlanghorn who don't make the assumption that the Name label is unique, even for running instances. It would be good if awspec could be used in these cases.
I'm not sure what the best solution would be - I'm not strong with rspec, and am new to the awspec codebase. So I'm hoping to learn something by exploring this issue.
-
In some cases, we would want the type to only return a running instances with the Name we've asked for. So we might want the ec2_finder to filter out terminated instances.
-
But in other cases, we might want to examine the instance even if it's terminated. Maybe we want to prove that an instance has been terminated.
-
In other cases, we might have different expectations about the state of the instance. Do we want to include instances that are still initializing? Ones that have failed to be created?
So what's the nice, rspec-like solution? Is it having multiple types? ec2
, running_ec2
, etc.? Or is it possible to pass options to the type, that can be used to filter what is selected, without looking ugly?
Should there be a type (or more than one type) that returns a list, like ec2_instances
? This would help people who don't assume Name is unique, and also those who might want to filter through the returned instances in different states.
from awspec.
I'm having a similar issue. The solution of testing for should be_terminated
doesn't help, because I'm not trying to test whether it's terminated.
For example, I have a spec like this:
describe ec2('My Server') do
it { should be_running }
end
My workflow is like this:
- Edit and apply terraform template
- Run tests
- Make a change to terraform that causes the server to be destroyed and a new instance to be created
- Run tests
Assuming my server was successfully recreated, I expect my tests to pass. Instead, I get:
1) private_instance ec2 'My Server' should be running
On host `10.0.2.225'
Failure/Error: it { should be_running }
NoMethodError:
undefined method `state' for nil:NilClass
# /var/lib/gems/2.3.0/gems/awspec-0.61.0/lib/awspec/type/ec2.rb:29:in `block (2 levels) in <class:Ec2>'
# /var/lib/gems/2.3.0/gems/serverspec-2.37.2/lib/serverspec/matcher/be_running.rb:7:in `block (2 levels) in <top (required)>'
# ./spec/gocd_server/private_instance_spec.rb:9:in `block (3 levels) in <top (required)>'
This is because the terminated instance with the same name still exists for a little while.
The issue seems to be in helper/finder/ec2.rb:31:
def find_ec2_status(id)
res = ec2_client.describe_instance_status({
instance_ids: [id]
})
res.instance_statuses.first if res.instance_statuses.count == 1
end
If res.instance_status.count is not 1 (as it will be when you rebuild a server with a given Name), then this returns nil.
At the very least, it should throw Awspec::DuplicatedResourceTypeError
. Better yet would be to return the running instance. But I can see this complicates things, as find_ec2 may be called in other situations where this behaviour isn't expected.
I'm happy to make a change and submit a pull request. But I'm not sure what the best solution is for the overall library.
from awspec.
For anyone else who needs a workaround to the terminated ec2 instance name issue, I created a little script to find the id of a running ec2 with the specified name.
So instead of:
require 'awspec'
describe ec2('nametag') do
it { should exist }
end
You can do:
require 'awspec'
require 'ec2_helper'
describe ec2(EC2Helper.GetIdFromName('nametag')) do
it { should exist }
end
make sure to add gem 'aws-sdk'
to your Gemfile
from awspec.
Thank you for your comment.
awspec can test terminated
instance.
describe ec2('my-ec2') do
it { should be_terminated }
end
And awspec need "unique" instance name (if same name instances exist, it should use instance-id).
If you want to test same name tag, you can use Aws::EC2::Client#wait_until
( see http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#wait_until-instance_method )
Best regards
from awspec.
Hi @kief
At the very least, it should throw Awspec::DuplicatedResourceTypeError.
That's exactly right.
I think A and B are different issues.
A. Terminated and running instances having the same name will cause tests to fail => wontfix
B. find_ec2_status should throw Awspec::DuplicatedResourceTypeError. => pull request wanted
from awspec.
Related Issues (20)
- API Gateway tests fail if more than 25 APIs in Gateway even though APIs exist HOT 2
- Cannot do a negative test for security groups HOT 4
- The format of stub files HOT 1
- Support for using have_record_set for a cname record that point to multiple weighted targets HOT 1
- Apigateway resource, probable bug in https://github.com/k1LoW/awspec/blob/master/lib/awspec/type/apigateway.rb#L34 HOT 1
- Add support for S3 bucket location
- Networkissue when using Proxy HOT 2
- rds_parameter_group parameter check fails with 'method_missing' HOT 3
- route53_hosted_zone parameter check fails with 'no implicit conversion of Hash into String' HOT 1
- Documentation for eks_nodegroup is not working properly
- Filter tests (Run chosen tests only) HOT 1
- several warnings during testing
- Subnet finder missing by_cidr method HOT 1
- Missing details for iam_role and iam_policy
- cannot install due missing aws-sdk-core version
- Error requiring awspec when using Ruby 3.1.0 HOT 2
- Does awspec support RDS Aurora? HOT 2
- Error executing request, Exception : ComputeEnvironments and MaxResults cannot both be set
- aws_sfn_state_machine not exists HOT 1
- An error occurred while loading ./spec/ec2_spec.rb. - Did you mean? rspec ./spec/spec_helper.rbFailure/Error: require 'awspec'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awspec.