39
40
'endpoint~ec2.cn-north-1.amazonaws.com',
44
'--output-format', '%(id)s'
46
with mock.patch("subprocess.check_output", return_value=results,
47
autospec=True) as co_mock:
48
ami = get_ami.query_ami("trusty", "amd64", region="cn-north-1")
49
self.assertEqual(ami, "ami-first")
50
co_mock.assert_called_once_with(expected_args)
52
def test_query_ami_daily_stream(self):
53
results = "ami-first\nami-second\nami-third\n"
57
'endpoint~ec2.us-east-1.amazonaws.com',
62
'--output-format', '%(id)s'
64
with mock.patch("subprocess.check_output", return_value=results,
65
autospec=True) as co_mock:
66
ami = get_ami.query_ami("trusty", "amd64", stream="daily")
46
'--output-format', '%(id)s'
48
with mock.patch("subprocess.check_output", return_value=results,
49
autospec=True) as co_mock:
50
ami = get_ami.query_ami("trusty", "amd64", "cn-north-1")
67
51
self.assertEqual(ami, "ami-first")
68
52
co_mock.assert_called_once_with(expected_args)
86
71
self.assertEqual(ami, "ami-first")
87
72
co_mock.assert_called_once_with(expected_args)
89
def test_query_ami_label(self):
90
results = "ami-first\nami-second\nami-third\n"
94
'endpoint~ec2.us-east-1.amazonaws.com',
100
'--output-format', '%(id)s'
102
with mock.patch("subprocess.check_output", return_value=results,
103
autospec=True) as co_mock:
104
ami = get_ami.query_ami("trusty", "amd64", label="release")
105
self.assertEqual(ami, "ami-first")
106
co_mock.assert_called_once_with(expected_args)
108
74
def test_query_ami_missing_tool(self):
109
75
error = OSError(errno.ENOENT, "not found")
110
76
message = "sstream-query tool not found, is it installed?"
118
84
def test_query_no_results(self):
120
"No amis for arch=amd64 release=precise root_store=ssd virt=pv"
121
" in region=us-east-1"
86
"No amis for arch=amd64 release=precise label=release"
87
" root_store=ssd virt=pv in region=us-east-1"
123
89
with mock.patch("subprocess.check_output", return_value="",
124
90
autospec=True) as co_mock: