Merge pull request #35467 from rallytime/bp-33518

Back-port #33518 to 2016.3
This commit is contained in:
Mike Place 2016-08-16 10:17:01 +09:00 committed by GitHub
commit d2dd78e25b
2 changed files with 61 additions and 10 deletions

View File

@ -55,16 +55,31 @@ def node_state(id_):
'''
Libcloud supported node states
'''
states = {0: 'RUNNING',
1: 'REBOOTING',
2: 'TERMINATED',
3: 'PENDING',
4: 'UNKNOWN',
5: 'STOPPED',
6: 'SUSPENDED',
7: 'ERROR',
8: 'PAUSED'}
return states[id_]
states_int = {
0: 'RUNNING',
1: 'REBOOTING',
2: 'TERMINATED',
3: 'PENDING',
4: 'UNKNOWN',
5: 'STOPPED',
6: 'SUSPENDED',
7: 'ERROR',
8: 'PAUSED'}
states_str = {
'running': 'RUNNING',
'rebooting': 'REBOOTING',
'starting': 'STARTING',
'terminated': 'TERMINATED',
'pending': 'PENDING',
'unknown': 'UNKNOWN',
'stopping': 'STOPPING',
'stopped': 'STOPPED',
'suspended': 'SUSPENDED',
'error': 'ERROR',
'paused': 'PAUSED',
'reconfiguring': 'RECONFIGURING'
}
return states_str[id_] if isinstance(id_, string_types) else states_int[id_]
def check_libcloud_version(reqver=LIBCLOUD_MINIMAL_VERSION, why=None):

View File

@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: `Anthony Shaw <anthonyshaw@apache.org>`
tests.unit.cloud.clouds.dimensiondata_test
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'''
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing Libs
from salttesting import TestCase
# Import Salt Libs
import salt.cloud.libcloudfuncs as libcloud
# Import Salt Testing Libs
from salttesting.helpers import ensure_in_syspath
ensure_in_syspath('../../')
class LibcloudTestCase(TestCase):
def test_node_state_libcloud_020(self):
state = libcloud.node_state(2)
self.assertEqual('TERMINATED', state)
def test_node_state_libcloud_100(self):
state = libcloud.node_state('terminated')
self.assertEqual('TERMINATED', state)
if __name__ == '__main__':
from unit import run_tests
run_tests(LibcloudTestCase, needs_daemon=False)