Beispiel #1
0
 def test_physnet_known(self):
     child = {
         'key': "/networking-vpp/state/vpp0/physnets/testnet",
         'value': "1",
         'expiration': None,
         'ttl': None,
         'modifiedIndex': 5,
         'createdIndex': 1,
         'newKey': False,
         'dir': False,
     }
     parent = {
         "node": {
             'key': "/networking-vpp",
             'value': None,
             'expiration': None,
             'ttl': None,
             'modifiedIndex': 5,
             'createdIndex': 1,
             'newKey': False,
             'dir': False,
         }
     }
     result = EtcdResult(**parent)
     result._children = [child]
     host = 'vpp0'
     physnet = 'testnet'
     self.mech.communicator.etcd_client.read.return_value = result
     assert(self.mech.physnet_known(host, physnet) is True), \
         "Return value for host [%s] and net [%s] should have been True" % (
             host, physnet)
Beispiel #2
0
 def test_find_physnets(self):
     child = {
         'key': "/networking-vpp/state/vpp0/physnets/testnet",
         'value': "1",
         'expiration': None,
         'ttl': None,
         'modifiedIndex': 5,
         'createdIndex': 1,
         'newKey': False,
         'dir': False,
     }
     parent = {
         "node": {
             'key': "/networking-vpp",
             'value': None,
             'expiration': None,
             'ttl': None,
             'modifiedIndex': 5,
             'createdIndex': 1,
             'newKey': False,
             'dir': False,
         }
     }
     result = EtcdResult(**parent)
     result._children = [child]
     self.etcd_client.etcd_client.read.return_value = result
     retval = self.etcd_client.find_physnets()
     assert ('vpp0', 'testnet') in retval, \
         "Return value should have contained ('vpp0', 'testnet')"
Beispiel #3
0
def data():
    obj = EtcdResult(
        **{
            u'action': u'GET',
            u'node': {
                u'modifiedIndex': 190,
                u'key': u'/clusters/test_uuid/data',
                u'value': '{"current_job": {"status": "test_status",'
                          '"job_id": "5e2d4a84-fdb8-4386-a0c4-c25e2de17d3c",'
                          '"job_name": "test_job"},'
                          '"status": "",'
                          '"short_name": "test_name",'
                          '"volume_profiling_flag": "enable",'
                          '"conf_overrides": "",'
                          '"integration_id": "test_uuid",'
                          '"errors": "[]",'
                          '"node_configuration": "",'
                          '"locked_by": {},'
                          '"last_sync": "2018-06-13 07:31:13.145381+00:00",'
                          '"volume_profiling_state": "enabled",'
                          '"public_network": "",'
                          '"is_managed": "yes",'
                          '"node_identifier": "[]",'
                          '"cluster_network": "172.28.128.0/24"}'
            }
        }
    )
    return obj
Beispiel #4
0
 def result_set(dirname, keys):
     dir_keys = keys
     for k in dir_keys:
         key_name = k['key']
         k['key'] = '{}{}'.format(dirname, key_name)
     d = dict(node=dict(
         key=dirname,
         expiration=None,
         ttl=None,
         modifiedIndex=6,
         createdIndex=2,
         newKey=False,
         dir=True,
         nodes=dir_keys
     ))
     res = EtcdResult(**d)
     res.etcd_index = 99
     return res
def nodes():
    obj = EtcdResult(
        **{
            u'action': u'GET',
            u'node': {
                u'modifiedIndex': 190,
                u'key': u'/clusters/test_uuid/nodes/abc',
                u'value': u'test'
            }
        })
    return obj
Beispiel #6
0
def return_hash():
    obj = EtcdResult(
        **{
            u'action': u'GET',
            u'node': {
                u'modifiedIndex': 190,
                u'key': u'/clusters/test_uuid/hash',
                u'value': u'13cf69912c5ee763caf4bf85bc7c8d7c'
            }
        })
    return obj
def gluster_servers():
    obj = EtcdResult(
        **{
            u'action': u'GET',
            u'node': {
                u'modifiedIndex': 190,
                u'key': u'/indexes/tags/gluster/server',
                u'value': u'["abc", "mno"]'
            }
        })
    return obj
def node_alerts():
    obj = EtcdResult(
        **{
            u'action': u'GET',
            u'node': {
                u'modifiedIndex': 190,
                u'key': u'/alerting/nodes/test_uuid',
                u'value': u'test'
            }
        })
    return obj
 def result_set(dirname, keys):
     dir_keys = keys
     for k in dir_keys:
         key_name = k["key"]
         k["key"] = "{}{}".format(dirname, key_name)
     d = dict(
         node=dict(
             key=dirname,
             expiration=None,
             ttl=None,
             modifiedIndex=6,
             createdIndex=2,
             newKey=False,
             dir=True,
             nodes=dir_keys,
         )
     )
     res = EtcdResult(**d)
     res.etcd_index = 99
     return res
Beispiel #10
0
 def fake_result(self):
     r = EtcdResult(None, {})
     r.value = global_data
     r.createdIndex = 1
     r.modifiedIndex = global_index
     r.etcd_index = global_index
     return r
def nodes():
    obj = EtcdResult(**{u'action': u'get',
                        u'node': {u'createdIndex': 20521,
                                  u'key': u'/clusters/test_uuid/nodes',
                                  u'modifiedIndex': 20521,
                                  u'nodes': [{u'createdIndex': 20521,
                                              u'modifiedIndex': 20521,
                                              u'key': u'/clusters/test_uuid'
                                                      u'/nodes/test_node1',
                                              u'dir': True}],
                                  u'dir': True}}
                     )
    return obj
def node_alerts():
    obj = EtcdResult(**{u'action': u'get',
                        u'node': {u'createdIndex': 82420,
                                  u'key': u'/alerting/nodes/test_node1',
                                  u'modifiedIndex': 82420,
                                  u'nodes': [{u'createdIndex': 82420,
                                              u'modifiedIndex': 82420,
                                              u'expiration': u'2018-06-14T15:'
                                                             u'02:54.34944151'
                                                             u'4Z',
                                              u'key': u'/alerting/nodes/'
                                                      u'test_node1/alert1',
                                              u'ttl': 172684,
                                              u'dir': True}],
                                  u'dir': True}}
                     )
    return obj
Beispiel #13
0
    def test_save_diags(self, m_subprocess, m_DatastoreClient, m_tarfile_open,
                        m_copytree, m_sh_command, m_socket, m_open, m_datetime,
                        os_path_isdir, m_os_mkdir, m_tempfile):
        """
        Test save_diags for calicoctl diags command
        """
        # Set up mock objects
        m_tempfile.mkdtemp.return_value = '/temp/dir'
        date_today = '2015-7-24_09_05_00'
        m_datetime.strftime.return_value = date_today
        m_socket.return_value = 'hostname'
        m_sh_command_return = Mock(autospec=True)
        m_sh_command.return_value = m_sh_command_return
        m_datetime.today.return_value = 'diags-07242015_090500.tar.gz'
        m_os_mkdir.return_value = True
        # The DatastoreClient contains an etcd Client
        # The etcd Client reads in a list of children of type EtcdResult
        # The children are accessed by calling get_subtree method on the etcd Client
        m_datastore_client = Mock(spec=DatastoreClient)
        m_datastore_client.etcd_client = Mock(spec=Client)
        m_datastore_data = Mock(spec=EtcdResult)
        m_child_1 = EtcdResult(node={'dir': True, 'key': 666})
        m_child_2 = EtcdResult(node={'key': 555, 'value': 999})
        m_datastore_data.get_subtree.return_value = [m_child_1, m_child_2]
        m_datastore_client.etcd_client.read.return_value = m_datastore_data
        m_DatastoreClient.return_value = m_datastore_client

        # Set up arguments
        log_dir = '/log/dir'
        temp_dir = '/temp/dir/'
        diags_dir = temp_dir + 'diagnostics'

        # Call method under test
        diags.save_diags(log_dir)

        # Assert
        m_subprocess.call.assert_called_once_with(
            ["docker", "exec", "calico-node", "pkill", "-SIGUSR1", "felix"])
        m_tempfile.mkdtemp.assert_called_once_with()
        m_os_mkdir.assert_called_once_with(diags_dir)
        m_open.assert_has_calls([
            call(diags_dir + '/date', 'w'),
            call().__enter__().write('DATE=%s' % date_today),
            call(diags_dir + '/hostname', 'w'),
            call().__enter__().write('hostname'),
            call(diags_dir + '/netstat', 'w'),
            call().__enter__().writelines(m_sh_command_return()),
            call(diags_dir + '/route', 'w'),
            call().__enter__().write('route --numeric\n'),
            call().__enter__().writelines(m_sh_command_return()),
            call().__enter__().write('ip route\n'),
            call().__enter__().writelines(m_sh_command_return()),
            call().__enter__().write('ip -6 route\n'),
            call().__enter__().writelines(m_sh_command_return()),
            call(diags_dir + '/iptables', 'w'),
            call().__enter__().writelines(m_sh_command_return()),
            call(diags_dir + '/ipset', 'w'),
            call().__enter__().writelines(m_sh_command_return()),
            call(diags_dir + '/etcd_calico', 'w'),
            call().__enter__().write('dir?, key, value\n'),
            call().__enter__().write('DIR,  666,\n'),
            call().__enter__().write('FILE, 555, 999\n')
        ],
                                any_order=True)
        m_sh_command.assert_has_calls([
            call('netstat'),
            call()(all=True, numeric=True),
            call('route'),
            call()(numeric=True),
            call('ip'),
            call()('route'),
            call()('-6', 'route'),
            call('iptables-save'),
            call()(),
            call('ipset'),
            call()('list')
        ])
        m_datastore_client.etcd_client.read.assert_called_once_with(
            '/calico', recursive=True)
        m_copytree.assert_called_once_with(log_dir,
                                           diags_dir + '/logs',
                                           ignore=ANY)
        m_tarfile_open.assert_called_once_with(temp_dir + date_today, 'w:gz')
 def fake_result(self):
     r = EtcdResult(None, {})
     r.value = global_data
     r.createdIndex = 1
     r.modifiedIndex = global_index
     return r