def get_list_servers(self):
        """[summary]

        Returns:
            [dict] -- [description]
        """

        keys = self.get_list_server_keys()
        list_bdds = []
        list_bams = []
        list_vmhosts = []
        for key in keys:
            if key.split('|')[0] == ServerType.BDDS:
                bdds = Bdds()
                bdds.set_from_memcache(
                    key, self.client.get(key).decode())
                list_bdds.append(bdds)
            elif key.split('|')[0] == ServerType.BAM:
                bam = Bam()
                bam.set_from_memcache(
                    key, self.client.get(key).decode())
                list_bams.append(bam)
            elif key.split('|')[0] == ServerType.VM_HOST:
                vm_host = VMHost()
                vm_host.set_from_memcache(
                    key, self.client.get(key).decode())
                list_vmhosts.append(vm_host)
        return list_bdds, list_bams, list_vmhosts
Exemple #2
0
 def test_set_from_memcache(self):
     """
     :param:
     :return:
     """
     call_class = Bdds("1", "2", "3", "4")
     key = "key|bam_ip|bam_id"
     value = "name|192.168.88.54|udf"
     call_class.set_from_memcache(key, value)
Exemple #3
0
 def test_set_from_bam_data(self):
     """
     :param:
     :return:
     """
     call_class = Bdds("1", "2", "3", "4")
     server_bam_data = {
         "id": "123",
         "name": "bdds169",
         "properties": "ups_ip_address=192.168.88.1,192.168.88.2|ups_snmp_configuration={'snmp_config': {'v1': {'status': 'enable', 'community_string': 'qqqq'}}, 'trap_oid': {'lowBattery': '1.3.6.1.4.1.318.0.7'}}|defaultInterfaceAddress=192.168.88.169|servicesIPv4Address=192.168.89.169|servicesIPv6Address=FDAC:1400:1::20|fullHostName=bdds169|profile=DNS_DHCP_INTEGRITY_BRANCH|"
     }
     call_class.set_from_bam_data(server_bam_data)
Exemple #4
0
 def test_bdds_get_memcache_value(self):
     """
     :param:
     :return:
     """
     id = 1111  # pylint:disable=invalid-name
     name = "BDDS1"
     udf = "aaa"
     ipv4_address = "192.1.1.1"
     bam_ip = "192.2.2.2"
     bdds = Bdds(id, name, udf, ipv4_address, bam_ip)
     actual = bdds.get_memcache_value()
     expected = "{}|{}|{}".format(name, ipv4_address, udf)
     self.assertEqual(expected, actual)
Exemple #5
0
 def test_bdds_get_memcache_key(self, mock_type_bdds):
     """
     :param:
     :return:
     """
     id = 1111  # pylint:disable=invalid-name
     name = "BDDS1"
     udf = "aaa"
     ipv4_address = "192.1.1.1"
     bam_ip = "192.2.2.2"
     BDDS = "BDDS"    # pylint:disable=invalid-name
     mock_type_bdds.BDDS = BDDS
     bdds = Bdds(id, name, udf, ipv4_address, bam_ip)
     actual = bdds.get_memcache_key()
     expected = "{}|{}|{}".format(BDDS, bam_ip, id)
     self.assertEqual(expected, actual)
Exemple #6
0
 def test__str__(self):
     id = 1111  # pylint:disable=invalid-name
     name = "BDDS1"
     udf = "aaa"
     ipv4_address = "192.1.1.1"
     bam_ip = "192.2.2.2"
     bdds = Bdds(id, name, udf, ipv4_address, bam_ip)
     expected = "{}|{}|{}|{}|{}".format(id, name, bam_ip, ipv4_address, udf)
     self.assertEqual(expected, str(bdds))
    def set_server(self, server, server_type, bam_ip=None, list_udf_names=[]):
        """[Set server to memcache]
        Arguments:
            server {[dict]} -- [server include:
                - bdds: id, name, type, properties
                - bam: id, name, ipv4_address]
            server_type {string} -- [BDDS or BAM] 
            bam_ip {string} -- [bam ipv4] (default: None)
            udf {dict} -- [description] (default: [])
        """
        logging.debug(
            "MemcachedNFV-Set_server-Server infor: {}-ServerType: {}-Bam_ip: {} "
            .format(str(server), server_type, bam_ip))

        try:
            if server_type == ServerType.BDDS:
                bdds = Bdds(bam_ip=bam_ip)
                bdds.set_from_bam_data(server, list_udf_names)
                key = bdds.get_memcache_key()
                value = bdds.get_memcache_value()
            elif server_type == ServerType.BAM:
                bam = Bam(name=server['name'],
                          ipv4_address=server['ipv4_address'])
                key = bam.get_memcache_key()
                value = bam.get_memcache_value()
            else:
                vm_host = VMHost(name=server['name'],
                                 ipv4_address=server['ipv4_address'])
                key = vm_host.get_memcache_key()
                value = vm_host.get_memcache_value()

            # Update to list server key
            self.update_list_server_key(server_type, key)
            self.client.set(key, value)
            logging.info("Added {} to memcache".format(key))
        except Exception as exception:
            logging.error("MemcachedNFV-Set_server-{}".format(exception))
            logging.error(traceback.format_exc())
            self.client.close()
    def test_collect_statistics(self, mock_get_memcached_config,
                                mock_memcached_nfv, mock_read_config_json_file,
                                mock_get_snmp_server_config_name):
        """
        :param:
        :return:
        """
        memcached_host, memcached_port = "192.168.88.170", 11211
        mock_get_memcached_config.return_value = memcached_host, memcached_port
        mem_nfv = mock.MagicMock()
        mock_memcached_nfv.return_value = mem_nfv

        id = 1111  # pylint:disable=invalid-name
        name = "BDDS1"
        udf = "aaa"
        ipv4_address = "192.1.1.1"
        bam_ip = "192.2.2.2"
        bdds = Bdds(id, name, udf, ipv4_address, bam_ip)
        bdds.name = mock.Mock()

        name = "BAM1"
        bam = mock.MagicMock()
        bam.name = mock.Mock()
        bam.ipv4_address = mock.Mock()

        name = "VM_HOST"
        vm = mock.MagicMock()
        vm.name = mock.Mock()
        vm.ipv4_address = mock.Mock()

        list_bdds, list_bam, list_vmhosts = ([bdds], [bam], [vm])
        mem_nfv.get_list_servers.return_value = list_bdds, list_bam, list_vmhosts
        snmp_config = {
            "common": {
                "port": 161,
                "snmp_version": "v2c",
                "snmp_community": "bcnCommunityV2C",
                "user_name": "gateway-user",
                "authen_protocol": "MD5",
                "authen_password": "******",
                "priv_protocol": "AES",
                "priv_password": "******"
            },
            "bbds_01": {
                "port": 161,
                "snmp_version": "v2c",
                "snmp_community": "bcnCommunityV2C",
                "user_name": "gateway-user",
                "authen_protocol": "MD5",
                "authen_password": "******",
                "priv_protocol": "AES",
                "priv_password": "******"
            }
        }
        mock_read_config_json_file.return_value = snmp_config
        bdds_config_name = "DemoConfig"
        mock_get_snmp_server_config_name.rerurn_value = bdds_config_name
        from statistics_collection.statistic_collection_run import collect_statistics  # pylint:disable=import-error
        actual = collect_statistics()
        expect = []
        self.assertEqual(actual, expect)