Skip to content

Commit f30c7af

Browse files
author
bryanwb
committed
Filter out unneeded status lines for AWS instances
1 parent 5c641a5 commit f30c7af

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

tests/test_vagrant.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,35 @@ def test_parse_status():
197197
assert goal == parsed, 'The parsing of the test listing did not match the goal.\nlisting={!r}\ngoal={!r}\nparsed_listing={!r}'.format(listing, goal, parsed)
198198

199199

200+
@with_setup(make_setup_vm(), teardown_vm)
201+
def test_parse_aws_status():
202+
'''
203+
Test the parsing the output of the `vagrant status` command for an aws instance.
204+
'''
205+
listing = '''1462351212,default,action,read_state,start
206+
1462351214,default,action,read_state,end
207+
1462351214,default,metadata,provider,aws
208+
1462351214,default,action,read_state,start
209+
1462351215,default,action,read_state,end
210+
1462351215,default,action,read_state,start
211+
1462351216,default,action,read_state,end
212+
1462351216,default,action,read_state,start
213+
1462351217,default,action,read_state,end
214+
1462351217,default,provider-name,aws
215+
1462351217,default,state,running
216+
1462351217,default,state-human-short,running
217+
1462351217,default,state-human-long,The EC2 instance is running. To stop this machine%!(VAGRANT_COMMA) you can run\\n`vagrant halt`. To destroy the machine%!(VAGRANT_COMMA) you can run `vagrant destroy`.
218+
1462351217,default,action,read_state,start
219+
1462351219,default,action,read_state,end
220+
1462351219,,ui,info,Current machine states:\\n\\ndefault (aws)\\n\\nThe EC2 instance is running. To stop this machine%!(VAGRANT_COMMA) you can run\\n`vagrant halt`. To destroy the machine%!(VAGRANT_COMMA) you can run `vagrant destroy`.
221+
'''
222+
# Can compare tuples to Status class b/c Status is a collections.namedtuple.
223+
goal = [('default', 'running', 'aws')]
224+
v = vagrant.Vagrant(TD)
225+
parsed = v._parse_status(listing)
226+
assert goal == parsed, 'The parsing of the test listing did not match the goal.\nlisting={!r}\ngoal={!r}\nparsed_listing={!r}'.format(listing, goal, parsed)
227+
228+
200229
@with_setup(make_setup_vm(), teardown_vm)
201230
def test_vm_status():
202231
'''

vagrant/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ def _parse_machine_readable_output(self, output):
852852
# vagrant 1.8 adds additional fields that aren't required,
853853
# and will break parsing if included in the status lines.
854854
# filter them out pending future implementation.
855-
parsed_lines = list(filter(lambda x: x[2] != "metadata" and x[2] != "ui", parsed_lines))
855+
parsed_lines = list(filter(lambda x: x[2] not in ["metadata", "ui", "action"], parsed_lines))
856856
return parsed_lines
857857

858858
def _parse_config(self, ssh_config):

0 commit comments

Comments
 (0)