Discussion:
[Libstoragemgmt-devel] [PATCH 0/4] Constants clean up.
Gris Ge
2014-08-27 11:55:53 UTC
Permalink
Just some constant rename.

Gris Ge (4):
Utils: New script to compare constants in Python and C library
Rename Disk.DISK_TYPE_XXX to Disk.DISK
C Library: Rename LSM_CAPABILITY_XXX to LSM_CAP_XXX
Python Library: Trivial change: Allow script to easily check constants

.../libstoragemgmt/libstoragemgmt_capabilities.h | 4 +-
c_binding/lsm_datatypes.cpp | 4 +-
plugin/ontap/ontap.py | 30 +-
plugin/sim/simarray.py | 32 +-
plugin/smispy/smis.py | 22 +-
python_binding/lsm/_data.py | 51 ++-
test/tester.c | 10 +-
tools/lsmcli/data_display.py | 26 +-
tools/utility/check_const.pl | 489 +++++++++++++++++++++
9 files changed, 580 insertions(+), 88 deletions(-)
create mode 100644 tools/utility/check_const.pl
--
2.1.0
Gris Ge
2014-08-27 11:55:54 UTC
Permalink
Sorry for hurting your eyes again with perl voodoo regex.

Generally this script compare constants in Python and C library using known
name conversion(please check py_name_2_c_name()):
1. Convert CaMel to CA_MEL
2. Convert System to SYSTEM
3. Convert Capabilities to CAP and etc using %PY_CLASS_NAME_CONV;

The report will be like:
=====
PASS lsm.Volume.REPLICATE_SNAPSHOT 1(1)
LSM_VOLUME_REPLICATE_SNAPSHOT 1(1)
PY_MISS ACCESS_GROUP_MASKED 502(502)
C_MISS lsm.Disk.STATUS_REMOVED 1 << 5(32)
FAIL lsm.Fake.FAKE_NAME 1 << 5(32)
LSM_FAKE_FAKE_NAME 0x000010(16)
=====

It found many missing, no failure in current code tree.
We will discuss and patch them later.

Signed-off-by: Gris Ge <***@redhat.com>
---
tools/utility/check_const.pl | 489 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 489 insertions(+)
create mode 100644 tools/utility/check_const.pl

diff --git a/tools/utility/check_const.pl b/tools/utility/check_const.pl
new file mode 100644
index 0000000..9e5a700
--- /dev/null
+++ b/tools/utility/check_const.pl
@@ -0,0 +1,489 @@
+#!/usr/bin/perl
+# Copyright (C) 2014 Red Hat, Inc.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+# USA
+#
+# Author: Gris Ge <***@redhat.com>
+#
+
+# This script compare public constants of lsm Python library files with C
+# library include files.
+
+# Naming scheme:
+# py_name # Constant name used in Python, example:
+# # 'lsm.System.STATUS_OK'
+#
+# py_value # The value of python constant.
+#
+# c_name # Constant name used in C, example:
+# # 'LSM_SYSTEM_STATUS_OK'
+#
+# c_value # The value of C constant. We stored the raw string.
+
+use strict;
+use warnings;
+
+use File::Basename;
+use Cwd 'abs_path';
+use Data::Dumper;
+
+my $LSM_CODE_BASE_DIR = dirname( dirname( dirname( abs_path($0) ) ) );
+my $PYTHON_LIB_DIR = "$LSM_CODE_BASE_DIR/python_binding/lsm";
+my $C_LIB_HEADER = "$LSM_CODE_BASE_DIR"
+ . "/c_binding/include/libstoragemgmt/libstoragemgmt.h";
+
+my $REGEX_VALUE_FORMAT = qr/
+ (?<NUM>(?&NUM_PAT))
+
+ (?(DEFINE)
+ # integer number
+ (?<NUM_INT>
+ [0-9]+
+ )
+ # Bit shift:
+ # 1 << 9
+ (?<NUM_BIT_SHIFT>
+ 1
+ [\ \t]+
+ <<
+ [\ \t]+
+ [0-9]+
+ )
+ # Hex number
+ (?<NUM_HEX>
+ 0x[0-9]+
+ )
+ (?<NUM_PAT>
+ (?&NUM_BIT_SHIFT) | (?&NUM_HEX) | (?&NUM_INT)
+ )
+ )
+/x;
+
+my $REGEX_C_CONST_FORMAT = qr/
+ ^
+ (?: (?&HEADER_PAT))
+ (?<CNAME>(?&CNAME_PAT))
+ (?: (?&SPLITER_PAT))
+ (?<NUM>(?&NUM_PAT))
+
+ (?(DEFINE)
+ # integer number
+ (?<NUM_INT>
+ [0-9]+
+ )
+ # Bit shift:
+ # 1 << 9
+ (?<NUM_BIT_SHIFT>
+ 1
+ [\ \t]+
+ <<
+ [\ \t]+
+ [0-9]+
+ )
+ # Hex number
+ # 0x0000000000000001
+ (?<NUM_HEX>
+ 0x[0-9]+
+ )
+ (?<NUM_PAT>
+ (?&NUM_BIT_SHIFT) | (?&NUM_HEX) | (?&NUM_INT)
+ )
+ (?<CNAME_PAT>
+ [A-Z][A-Z_]+
+ )
+ (?<HEADER1>
+ [\ \t]*
+ )
+ (?<HEADER2>
+ \#define[\ \t]+
+ )
+ (?<HEADER_PAT>
+ (?&HEADER1) | (?&HEADER2)
+ )
+ (?<SPLITER_PAT>
+ [\ \t]*
+ [=]*
+ [\ \t]*
+ )
+ )
+/x;
+
+my %PY_CLASS_NAME_CONV = (
+ 'Capabilities' => 'CAP',
+ 'ErrorNumber' => 'ERR',
+ 'JobStatus' => 'JOB',
+ 'ErrorLevel' => 'ERR_LEVEL',
+);
+
+my $REF_RESULT = {
+ 'pass' => {},
+ 'fail' => {},
+ 'c_missing' => {},
+ 'py_missing' => {},
+ 'c_const_hash' => {},
+ 'py_const_hash' => {},
+ 'known_c_to_py_name' => {},
+ 'known_py_to_c_name' => {},
+};
+
+# $REF_RESULT = {
+# 'pass' => {
+# $py_name => 1, # Just for deduplication.
+# },
+# 'fail' => {
+# $py_name => 1, # Just for deduplication.
+# },
+# 'c_missing' => {
+# $py_name => 1,
+# },
+# 'py_missing' => {
+# $c_name => 1,
+# },
+# 'py_const_hash' => {
+# $py_name => $py_value,
+# },
+# 'c_const_hash' => {
+# $c_name => $c_value,
+# },
+# 'known_c_to_py_name' => {
+# $c_name => $py_name,
+# }
+# }
+#
+
+$|++;
+
+sub is_in_array($$) {
+ my $ref_array = shift;
+ my $item = shift;
+ return 1 if grep { $_ eq $item } @{$ref_array};
+ return undef;
+}
+
+sub py_name_2_c_name($) {
+
+ # We do these conversion:
+ # 1. Convert CaMel to CA_MEL
+ # 2. Convert System to SYSTEM
+ # 3. Convert Capabilities to CAP and etc using %PY_CLASS_NAME_CONV;
+ my $py_name = shift;
+ if ( $py_name =~ /^lsm\.([a-zA-Z]+)\.([A-Z_]+)$/ ) {
+ my $py_class_name = $1;
+ my $py_var_name = $2;
+
+ # Convert camel class name
+ if (defined $PY_CLASS_NAME_CONV{$py_class_name}){
+ return sprintf "LSM_%s_%s",
+ $PY_CLASS_NAME_CONV{$py_class_name}, $py_var_name;
+ }
+ if ( $py_class_name =~ /^[A-Z][a-z]+$/ ) {
+ $py_class_name =~ tr/[a-z]/[A-Z]/;
+ return sprintf "LSM_%s_%s", $py_class_name, $py_var_name;
+ }
+ if ( $py_class_name =~ /^([A-Z][a-z]+)([A-Z][a-z]+)$/ ) {
+ $py_class_name = sprintf "%s_%s", $1, $2;
+ $py_class_name =~ tr/[a-z]/[A-Z]/;
+ return sprintf "LSM_%s_%s", $py_class_name, $py_var_name;
+ }
+ }
+
+ die "FAIL: Ilegal python constant name '$py_name'.\n";
+}
+
+sub _parse_c_init_header($){
+ # Take initial C header file and read its sub header files
+ # Return a reference of array containing file path.
+ my $init_header = shift;
+ my $folder_path = dirname($init_header);
+ open my $init_header_fd, "<", $init_header
+ or die "FAIL: Failed to open $init_header $!\n";
+ my @rc = ();
+ map{
+ push @rc, "$folder_path/$1" if /#include "([^"]+)"/;
+ }<$init_header_fd>;
+ return \@rc;
+}
+
+sub _get_c_constants($){
+ my $c_header = shift;
+ open my $c_header_fd, "<", $c_header
+ or die "FAIL: Failed to open $c_header $!\n";
+ my %rc = ();
+ map{
+ $rc{$+{'CNAME'}} = $+{'NUM'} if /$REGEX_C_CONST_FORMAT/;
+ }<$c_header_fd>;
+ return \%rc;
+}
+
+sub parse_out_c_const() {
+
+ # Return a reference like this:
+ # {
+ # $c_name => $value,
+ # }
+ my $ref_sub_c_headers = _parse_c_init_header($C_LIB_HEADER);
+ my $ref_c_name_2_value = {};
+ foreach my $cur_c_header (@{$ref_sub_c_headers}){
+ my $ref_tmp = _get_c_constants($cur_c_header);
+ foreach my $key_name (keys %{$ref_tmp}){
+ $ref_c_name_2_value->{$key_name} = $ref_tmp->{$key_name};
+ }
+ }
+ return $ref_c_name_2_value;
+}
+
+sub _parse_py_init_file($) {
+
+ # Return a reference of array containging file path of sub python module.
+ my $init_file = shift;
+ open my $init_fd, "<", $init_file
+ or die "FAIL: Failed to open $init_file: $!\n";
+ my $folder_path = dirname($init_file);
+ my @rc1 = ();
+ my @rc2 = ();
+ my @lines = ();
+
+ # Merge multiline codes
+ foreach my $line (<$init_fd>) {
+ chomp $line;
+ if ( $line =~ /^[^ ]/ ) {
+ push @lines, $line;
+ }
+ else {
+ $lines[-1] .= $line;
+ }
+ }
+ close $init_fd;
+
+ foreach my $line (@lines) {
+ if ( $line =~ /from ([^ ]+) import (.+)$/ ) {
+ push @rc1, sprintf "%s/%s.py", $folder_path, $1;
+ my $class_line = $2;
+ while ( $class_line =~ /([A-Z][a-zA-Z]+)[, \\]*/g ) {
+ push @rc2, $1;
+ }
+ }
+ }
+ return \@rc1, \@rc2;
+}
+
+sub _get_py_class_consts($$){
+ # Take $file_path and $ref_classes
+ # Return reference of hash:
+ # {
+ # $py_name => $value,
+ # }
+ my $py_file = shift;
+ my $ref_classes = shift;
+
+ open my $py_fd, "<", $py_file
+ or die "FAIL: Failed to open $py_file: $!\n";
+ my %rc_hash = ();
+ my $cur_class_name = undef;
+ my $current_idention = undef;
+ foreach my $line (<$py_fd>){
+ chomp $line;
+ if ($line =~ /^([ ]*)class[ ]+([^\(]+)\(/){
+ $current_idention = $1;
+ $cur_class_name = $2;
+ unless (is_in_array($ref_classes, $cur_class_name)){
+ $cur_class_name = undef;
+ next;
+ }
+ }
+ unless(defined $cur_class_name){
+ next;
+ }
+ if ($line =~ /^$current_idention
+ [\ ]+
+ ([A-Z][A-Z\_]+)
+ [\ ]*=[\ ]*
+ ($REGEX_VALUE_FORMAT)/x){
+ my $var_name = $1;
+ my $py_value = $2;
+ my $py_name = sprintf "lsm.%s.%s", $cur_class_name, $var_name;
+ $rc_hash{$py_name} = $py_value;
+ }
+ }
+ close $py_fd;
+ return \%rc_hash;
+}
+
+sub parse_out_py_const() {
+
+ # Return a reference like this:
+ # {
+ # $py_name => $value,
+ # }
+ my ( $ref_sub_files, $ref_classes ) =
+ _parse_py_init_file("$PYTHON_LIB_DIR/__init__.py");
+
+ my $ref_py_name_2_value = {};
+ foreach my $cur_py_file (@{$ref_sub_files}){
+ my $ref_tmp = _get_py_class_consts($cur_py_file, $ref_classes);
+ foreach my $key_name (keys %{$ref_tmp}){
+ $ref_py_name_2_value->{$key_name} = $ref_tmp->{$key_name};
+ }
+ }
+ return $ref_py_name_2_value;
+}
+
+sub value_str_to_int($) {
+ my $raw_value = shift;
+ unless ( defined $raw_value ) {
+ return undef;
+ }
+ if ( $raw_value =~ /^[0-9]+$/ ) {
+ return $raw_value;
+ }
+ if ( $raw_value =~ /^0x[0-9]+$/ ) {
+ return hex $raw_value;
+ }
+ if ( $raw_value =~ /^([0-9]+) +<< +([0-9]+)$/ ) {
+ return $1 << $2;
+ }
+ die "FAIL: Failed to convert $raw_value to integer\n";
+}
+
+sub record_result($$$$) {
+
+ # Take ($py_name, $py_value, $c_name, $c_value)
+ # Update $REF_RESULT
+ my $py_name = shift;
+ my $py_value = shift;
+ my $c_name = shift;
+ my $c_value = shift;
+ my $real_py_value = undef;
+ my $real_c_value = undef;
+
+ if ( ( defined $py_name ) && ( defined $py_value ) ) {
+ $real_py_value = value_str_to_int($py_value);
+ $REF_RESULT->{'py_const_hash'}->{$py_name} = sprintf "%s(%s)",
+ $py_value, $real_py_value;
+ }
+ if ( ( defined $c_name ) && ( defined $c_value ) ) {
+ $real_c_value = value_str_to_int($c_value);
+ $REF_RESULT->{'c_const_hash'}->{$c_name} = sprintf "%s(%s)", $c_value,
+ $real_c_value;
+ }
+
+ unless ($py_name) {
+ my $known_py_name = $REF_RESULT->{'known_c_to_py_name'}->{$c_name};
+ return 1 if $known_py_name; # Already checked.
+ $REF_RESULT->{'py_missing'}->{$c_name} = 'unknown';
+ return 1;
+ }
+
+ unless ($c_name) {
+
+ # ilegal python variable name, result already updated by
+ # py_name_2_c_name()
+ return 1;
+ }
+
+ $REF_RESULT->{'known_c_to_py_name'}->{$c_name} = $py_name;
+ $REF_RESULT->{'known_py_to_c_name'}->{$py_name} = $c_name;
+
+ unless ( defined $py_value ) {
+
+ # value for py_value will never be undef, just in case.
+ $REF_RESULT->{'py_missing'}->{$c_name} = $py_value;
+ return 1;
+ }
+
+ unless ( defined $c_value ) {
+ $REF_RESULT->{'c_missing'}->{$py_name} = $c_name;
+ return 1;
+ }
+ if ( $real_py_value == $real_c_value ) {
+ $REF_RESULT->{'pass'}->{$py_name} = 1;
+ }
+ else {
+ $REF_RESULT->{'fail'}->{$py_name} = 1;
+ }
+ 1;
+}
+
+sub show_result() {
+ my $format = "%-10s%-60s %s\n";
+ my @pass_py_names = sort keys %{ $REF_RESULT->{'pass'} };
+ my @fail_py_names = sort keys %{ $REF_RESULT->{'fail'} };
+ my @py_missing_c_names = sort keys %{ $REF_RESULT->{'py_missing'} };
+ my @c_missing_py_names = sort keys %{ $REF_RESULT->{'c_missing'} };
+ my $ref_py_name_2_c_name = $REF_RESULT->{'known_py_to_c_name'};
+ my $ref_py_name_2_value = $REF_RESULT->{'py_const_hash'};
+ my $ref_c_name_2_value = $REF_RESULT->{'c_const_hash'};
+
+ # Header
+ printf $format, '#'x8, 'Name', 'Value';
+ print "\n";
+ foreach my $py_name (@pass_py_names) {
+ my $py_value = $ref_py_name_2_value->{$py_name};
+ my $c_name = $ref_py_name_2_c_name->{$py_name};
+ my $c_value = $ref_c_name_2_value->{$c_name};
+ printf ($format, "PASS", $py_name, $py_value);
+ printf ($format, " ", $c_name, $c_value);
+ }
+ foreach my $c_name (@py_missing_c_names) {
+ my $py_name = '-' x 8;
+ my $py_value = '-' x 8;
+ my $c_value = $ref_c_name_2_value->{$c_name};
+ printf ($format, "PY_MISS", $c_name, $c_value);
+ }
+ foreach my $py_name (@c_missing_py_names) {
+ my $c_name = '-' x 8;
+ my $c_value = '-' x 8;
+ my $py_value = $ref_py_name_2_value->{$py_name};
+ printf ($format, "C_MISS", $py_name, $py_value);
+ }
+ foreach my $py_name (@fail_py_names) {
+ my $py_value = $ref_py_name_2_value->{$py_name};
+ my $c_name = $ref_py_name_2_c_name->{$py_name};
+ my $c_value = $ref_c_name_2_value->{$c_name};
+ printf ($format, "FAIL", $py_name, $py_value);
+ printf ($format, " ", $c_name, $c_value);
+ }
+ 1;
+}
+
+sub main() {
+ my $ref_py_const_hash = parse_out_py_const();
+ my $ref_c_const_hash = parse_out_c_const();
+ map {
+ my $py_name = $_;
+ my $c_name = py_name_2_c_name($py_name);
+ record_result(
+ $py_name, $ref_py_const_hash->{$py_name},
+ $c_name, $ref_c_const_hash->{$c_name}
+ )
+ } keys %{$ref_py_const_hash};
+
+ map {
+ my $c_name = $_;
+
+ # We don't have a way to convert C constant name to python one.
+ # We just treat all C constant as missing if not marked by previous
+ # check.
+ record_result( undef, undef, $c_name, $ref_c_const_hash->{$c_name} )
+ } keys %{$ref_c_const_hash};
+ show_result();
+ exit 1
+ if ( %{ $REF_RESULT->{'fail'} }
+ || %{ $REF_RESULT->{'c_missing'} }
+ || %{ $REF_RESULT->{'py_missing'} } );
+ exit 0;
+}
+
+main();
--
2.1.0
Gris Ge
2014-08-27 11:55:55 UTC
Permalink
* Just to match C library name:
LSM_DISK_TYPE_XXX

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/ontap/ontap.py | 30 +++++++++++++++---------------
plugin/sim/simarray.py | 32 ++++++++++++++++----------------
plugin/smispy/smis.py | 22 +++++++++++-----------
python_binding/lsm/_data.py | 28 ++++++++++++++--------------
tools/lsmcli/data_display.py | 26 +++++++++++++-------------
5 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/plugin/ontap/ontap.py b/plugin/ontap/ontap.py
index c13caec..7a2c397 100644
--- a/plugin/ontap/ontap.py
+++ b/plugin/ontap/ontap.py
@@ -198,20 +198,20 @@ class Ontap(IStorageAreaNetwork, INfs):
s['access-time'])

_NA_DISK_TYPE_TO_LSM = {
- 'ATA': Disk.DISK_TYPE_ATA,
- 'BSAS': Disk.DISK_TYPE_SATA,
- 'EATA': Disk.DISK_TYPE_ATA,
- 'FCAL': Disk.DISK_TYPE_FC,
- 'FSAS': Disk.DISK_TYPE_NL_SAS,
- 'LUN': Disk.DISK_TYPE_OTHER,
- 'MSATA': Disk.DISK_TYPE_SATA,
- 'SAS': Disk.DISK_TYPE_SAS,
- 'SATA': Disk.DISK_TYPE_SATA,
- 'SCSI': Disk.DISK_TYPE_SCSI,
- 'SSD': Disk.DISK_TYPE_SSD,
- 'XATA': Disk.DISK_TYPE_ATA,
- 'XSAS': Disk.DISK_TYPE_SAS,
- 'unknown': Disk.DISK_TYPE_UNKNOWN,
+ 'ATA': Disk.TYPE_ATA,
+ 'BSAS': Disk.TYPE_SATA,
+ 'EATA': Disk.TYPE_ATA,
+ 'FCAL': Disk.TYPE_FC,
+ 'FSAS': Disk.TYPE_NL_SAS,
+ 'LUN': Disk.TYPE_OTHER,
+ 'MSATA': Disk.TYPE_SATA,
+ 'SAS': Disk.TYPE_SAS,
+ 'SATA': Disk.TYPE_SATA,
+ 'SCSI': Disk.TYPE_SCSI,
+ 'SSD': Disk.TYPE_SSD,
+ 'XATA': Disk.TYPE_ATA,
+ 'XSAS': Disk.TYPE_SAS,
+ 'unknown': Disk.TYPE_UNKNOWN,
}

@staticmethod
@@ -222,7 +222,7 @@ class Ontap(IStorageAreaNetwork, INfs):
na_disk_type = na_disk['effective-disk-type']
if na_disk_type in Ontap._NA_DISK_TYPE_TO_LSM.keys():
return Ontap._NA_DISK_TYPE_TO_LSM[na_disk_type]
- return Disk.DISK_TYPE_UNKNOWN
+ return Disk.TYPE_UNKNOWN

@staticmethod
def _disk_id(na_disk):
diff --git a/plugin/sim/simarray.py b/plugin/sim/simarray.py
index 8d5ddf0..f60905d 100644
--- a/plugin/sim/simarray.py
+++ b/plugin/sim/simarray.py
@@ -73,19 +73,19 @@ class PoolRAID(object):
MEMBER_TYPE_POOL = 2

_MEMBER_TYPE_2_DISK_TYPE = {
- MEMBER_TYPE_DISK: Disk.DISK_TYPE_UNKNOWN,
- MEMBER_TYPE_DISK_MIX: Disk.DISK_TYPE_UNKNOWN,
- MEMBER_TYPE_DISK_ATA: Disk.DISK_TYPE_ATA,
- MEMBER_TYPE_DISK_SATA: Disk.DISK_TYPE_SATA,
- MEMBER_TYPE_DISK_SAS: Disk.DISK_TYPE_SAS,
- MEMBER_TYPE_DISK_FC: Disk.DISK_TYPE_FC,
- MEMBER_TYPE_DISK_SOP: Disk.DISK_TYPE_SOP,
- MEMBER_TYPE_DISK_SCSI: Disk.DISK_TYPE_SCSI,
- MEMBER_TYPE_DISK_NL_SAS: Disk.DISK_TYPE_NL_SAS,
- MEMBER_TYPE_DISK_HDD: Disk.DISK_TYPE_HDD,
- MEMBER_TYPE_DISK_SSD: Disk.DISK_TYPE_SSD,
- MEMBER_TYPE_DISK_HYBRID: Disk.DISK_TYPE_HYBRID,
- MEMBER_TYPE_DISK_LUN: Disk.DISK_TYPE_LUN,
+ MEMBER_TYPE_DISK: Disk.TYPE_UNKNOWN,
+ MEMBER_TYPE_DISK_MIX: Disk.TYPE_UNKNOWN,
+ MEMBER_TYPE_DISK_ATA: Disk.TYPE_ATA,
+ MEMBER_TYPE_DISK_SATA: Disk.TYPE_SATA,
+ MEMBER_TYPE_DISK_SAS: Disk.TYPE_SAS,
+ MEMBER_TYPE_DISK_FC: Disk.TYPE_FC,
+ MEMBER_TYPE_DISK_SOP: Disk.TYPE_SOP,
+ MEMBER_TYPE_DISK_SCSI: Disk.TYPE_SCSI,
+ MEMBER_TYPE_DISK_NL_SAS: Disk.TYPE_NL_SAS,
+ MEMBER_TYPE_DISK_HDD: Disk.TYPE_HDD,
+ MEMBER_TYPE_DISK_SSD: Disk.TYPE_SSD,
+ MEMBER_TYPE_DISK_HYBRID: Disk.TYPE_HYBRID,
+ MEMBER_TYPE_DISK_LUN: Disk.TYPE_LUN,
}

@staticmethod
@@ -662,14 +662,14 @@ class SimData(object):
d_id = SimData._disk_id(i)
d_size = disk_size_2t
d_name = "SATA Disk %0*d" % (D_FMT, i)
- d_type = Disk.DISK_TYPE_SATA
+ d_type = Disk.TYPE_SATA

if 2 <= i <= 8:
d_name = "SAS Disk %0*d" % (D_FMT, i)
- d_type = Disk.DISK_TYPE_SAS
+ d_type = Disk.TYPE_SAS
elif 9 <= i:
d_name = "SSD Disk %0*d" % (D_FMT, i)
- d_type = Disk.DISK_TYPE_SSD
+ d_type = Disk.TYPE_SSD
if i <= 13:
d_size = disk_size_512g

diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 41cf94e..f03a257 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -284,11 +284,11 @@ class Smis(IStorageAreaNetwork):
DMTF_DISK_TYPE_HYBRID = 4

_DMTF_DISK_TYPE_2_LSM = {
- DMTF_DISK_TYPE_UNKNOWN: Disk.DISK_TYPE_UNKNOWN,
- DMTF_DISK_TYPE_OTHER: Disk.DISK_TYPE_OTHER,
- DMTF_DISK_TYPE_HDD: Disk.DISK_TYPE_HDD,
- DMTF_DISK_TYPE_SSD: Disk.DISK_TYPE_SSD,
- DMTF_DISK_TYPE_HYBRID: Disk.DISK_TYPE_HYBRID,
+ DMTF_DISK_TYPE_UNKNOWN: Disk.TYPE_UNKNOWN,
+ DMTF_DISK_TYPE_OTHER: Disk.TYPE_OTHER,
+ DMTF_DISK_TYPE_HDD: Disk.TYPE_HDD,
+ DMTF_DISK_TYPE_SSD: Disk.TYPE_SSD,
+ DMTF_DISK_TYPE_HYBRID: Disk.TYPE_HYBRID,
}

@staticmethod
@@ -296,7 +296,7 @@ class Smis(IStorageAreaNetwork):
if dmtf_disk_type in Smis._DMTF_DISK_TYPE_2_LSM.keys():
return Smis._DMTF_DISK_TYPE_2_LSM[dmtf_disk_type]
else:
- return Disk.DISK_TYPE_UNKNOWN
+ return Disk.TYPE_UNKNOWN

DMTF_STATUS_UNKNOWN = 0
DMTF_STATUS_OTHER = 1
@@ -3048,7 +3048,7 @@ class Smis(IStorageAreaNetwork):
name = ''
block_size = Disk.BLOCK_SIZE_NOT_FOUND
num_of_block = Disk.BLOCK_COUNT_NOT_FOUND
- disk_type = Disk.DISK_TYPE_UNKNOWN
+ disk_type = Disk.TYPE_UNKNOWN
status_info = ''
sys_id = self._sys_id_child(cim_disk)

@@ -3071,9 +3071,9 @@ class Smis(IStorageAreaNetwork):
if 'Caption' in cim_disk:
# EMC VNX introduced NL_SAS disk.
if cim_disk['Caption'] == 'NL_SAS':
- disk_type = Disk.DISK_TYPE_NL_SAS
+ disk_type = Disk.TYPE_NL_SAS

- if disk_type == Disk.DISK_TYPE_UNKNOWN and 'DiskType' in cim_disk:
+ if disk_type == Disk.TYPE_UNKNOWN and 'DiskType' in cim_disk:
disk_type = \
Smis.dmtf_disk_type_2_lsm_disk_type(cim_disk['DiskType'])

@@ -3088,9 +3088,9 @@ class Smis(IStorageAreaNetwork):
if 'CreationClassName' in cim_pes[0]:
ccn = cim_pes[0]['CreationClassName']
if ccn == 'LSIESG_TargetSATAProtocolEndpoint':
- disk_type = Disk.DISK_TYPE_SATA
+ disk_type = Disk.TYPE_SATA
if ccn == 'LSIESG_TargetSASProtocolEndpoint':
- disk_type = Disk.DISK_TYPE_SAS
+ disk_type = Disk.TYPE_SAS

new_disk = Disk(self._disk_id(cim_disk), name, disk_type, block_size,
num_of_block, status, sys_id)
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index ef2483d..8978395 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -161,26 +161,26 @@ class Disk(IData):
BLOCK_COUNT_NOT_FOUND = -1
BLOCK_SIZE_NOT_FOUND = -1

- DISK_TYPE_UNKNOWN = 0
- DISK_TYPE_OTHER = 1
- DISK_TYPE_NOT_APPLICABLE = 2
- DISK_TYPE_ATA = 3 # IDE disk which is seldomly used.
- DISK_TYPE_SATA = 4
- DISK_TYPE_SAS = 5
- DISK_TYPE_FC = 6
- DISK_TYPE_SOP = 7 # SCSI over PCIe(SSD)
- DISK_TYPE_SCSI = 8
- DISK_TYPE_LUN = 9 # Remote LUN was treated as a disk.
+ TYPE_UNKNOWN = 0
+ TYPE_OTHER = 1
+ TYPE_NOT_APPLICABLE = 2
+ TYPE_ATA = 3 # IDE disk which is seldomly used.
+ TYPE_SATA = 4
+ TYPE_SAS = 5
+ TYPE_FC = 6
+ TYPE_SOP = 7 # SCSI over PCIe(SSD)
+ TYPE_SCSI = 8
+ TYPE_LUN = 9 # Remote LUN was treated as a disk.

# Due to complesity of disk types, we are defining these beside DMTF
# standards:
- DISK_TYPE_NL_SAS = 51 # Near-Line SAS==SATA disk + SAS port.
+ TYPE_NL_SAS = 51 # Near-Line SAS==SATA disk + SAS port.

# in DMTF CIM 2.34.0+ CIM_DiskDrive['DiskType'], they also defined
# SSD and HYBRID disk type. We use it as faillback.
- DISK_TYPE_HDD = 52 # Normal HDD
- DISK_TYPE_SSD = 53 # Solid State Drive
- DISK_TYPE_HYBRID = 54 # uses a combination of HDD and SSD
+ TYPE_HDD = 52 # Normal HDD
+ TYPE_SSD = 53 # Solid State Drive
+ TYPE_HYBRID = 54 # uses a combination of HDD and SSD

STATUS_UNKNOWN = 1 << 0
STATUS_OK = 1 << 1
diff --git a/tools/lsmcli/data_display.py b/tools/lsmcli/data_display.py
index 7f4100e..cc1732f 100644
--- a/tools/lsmcli/data_display.py
+++ b/tools/lsmcli/data_display.py
@@ -160,19 +160,19 @@ def vol_rep_type_str_to_type(vol_rep_type_str):


_DISK_TYPE_CONV = {
- Disk.DISK_TYPE_UNKNOWN: 'UNKNOWN',
- Disk.DISK_TYPE_OTHER: 'Other',
- Disk.DISK_TYPE_NOT_APPLICABLE: 'Not applicable',
- Disk.DISK_TYPE_ATA: 'ATA',
- Disk.DISK_TYPE_SATA: 'SATA',
- Disk.DISK_TYPE_SAS: 'SAS',
- Disk.DISK_TYPE_FC: 'FC',
- Disk.DISK_TYPE_SOP: 'SCSI Over PCI-E(SSD)',
- Disk.DISK_TYPE_NL_SAS: 'NL_SAS',
- Disk.DISK_TYPE_HDD: 'HDD',
- Disk.DISK_TYPE_SSD: 'SSD',
- Disk.DISK_TYPE_HYBRID: 'Hybrid',
- Disk.DISK_TYPE_LUN: 'Remote LUN',
+ Disk.TYPE_UNKNOWN: 'UNKNOWN',
+ Disk.TYPE_OTHER: 'Other',
+ Disk.TYPE_NOT_APPLICABLE: 'Not applicable',
+ Disk.TYPE_ATA: 'ATA',
+ Disk.TYPE_SATA: 'SATA',
+ Disk.TYPE_SAS: 'SAS',
+ Disk.TYPE_FC: 'FC',
+ Disk.TYPE_SOP: 'SCSI Over PCI-E(SSD)',
+ Disk.TYPE_NL_SAS: 'NL_SAS',
+ Disk.TYPE_HDD: 'HDD',
+ Disk.TYPE_SSD: 'SSD',
+ Disk.TYPE_HYBRID: 'Hybrid',
+ Disk.TYPE_LUN: 'Remote LUN',
}
--
2.1.0
Gris Ge
2014-08-27 11:55:57 UTC
Permalink
* No API changes.
* Just make the life of constant checker script easier.

Signed-off-by: Gris Ge <***@redhat.com>
---
python_binding/lsm/_data.py | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 8978395..9f5c723 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -239,13 +239,18 @@ class Volume(IData):
SUPPORTED_SEARCH_KEYS = ['id', 'system_id', 'pool_id']

#Replication types
- (REPLICATE_UNKNOWN, REPLICATE_SNAPSHOT, REPLICATE_CLONE, REPLICATE_COPY,
- REPLICATE_MIRROR_SYNC, REPLICATE_MIRROR_ASYNC) = \
- (-1, 1, 2, 3, 4, 5)
+ REPLICATE_UNKNOWN = -1
+ REPLICATE_SNAPSHOT = 1
+ REPLICATE_CLONE = 2
+ REPLICATE_COPY = 3
+ REPLICATE_MIRROR_SYNC = 4
+ REPLICATE_MIRROR_ASYNC =5

#Provisioning types
- (PROVISION_UNKNOWN, PROVISION_THIN, PROVISION_FULL, PROVISION_DEFAULT) = \
- (-1, 1, 2, 3)
+ PROVISION_UNKNOWN = -1
+ PROVISION_THIN = 1
+ PROVISION_FULL = 2
+ PROVISION_DEFAULT = 3

ADMIN_STATE_DISABLED = 0
ADMIN_STATE_ENABLED = 1
@@ -399,7 +404,7 @@ class FsSnapshot(IData):
class NfsExport(IData):
SUPPORTED_SEARCH_KEYS = ['id', 'fs_id']
ANON_UID_GID_NA = -1
- ANON_UID_GID_ERROR = (ANON_UID_GID_NA - 1)
+ ANON_UID_GID_ERROR = -2

def __init__(self, _id, _fs_id, _export_path, _auth, _root, _rw, _ro,
_anonuid, _anongid, _options, _plugin_data=None):
@@ -592,10 +597,8 @@ class TargetPort(IData):


class Capabilities(IData):
- (
- UNSUPPORTED, # Not supported
- SUPPORTED # Supported
- ) = (0, 1)
+ UNSUPPORTED = 0
+ SUPPORTED = 1

_NUM = 512 # Indicate the maximum capability integer
--
2.1.0
Gris Ge
2014-08-27 11:55:56 UTC
Permalink
* Rename LSM_CAPABILITY_SUPPORTED to LSM_CAP_SUPPORTED
* Rename LSM_CAPABILITY_UNSUPPORTED to LSM_CAP_UNSUPPORTED
* Just matching with other LSM_CAP_XXX constants naming scheme.

Signed-off-by: Gris Ge <***@redhat.com>
---
c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h | 4 ++--
c_binding/lsm_datatypes.cpp | 4 ++--
test/tester.c | 10 +++++-----
3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h b/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
index 818c8b2..62c25ac 100644
--- a/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
+++ b/c_binding/include/libstoragemgmt/libstoragemgmt_capabilities.h
@@ -31,8 +31,8 @@ extern "C" {
/*Note: Domain is 0..255 */
/** \enum lsm_capability_value_type Possible values for supported feature*/
typedef enum {
- LSM_CAPABILITY_UNSUPPORTED = 0, /**< Feature is not supported */
- LSM_CAPABILITY_SUPPORTED = 1 /**< Feature is supported */
+ LSM_CAP_UNSUPPORTED = 0, /**< Feature is not supported */
+ LSM_CAP_SUPPORTED = 1 /**< Feature is supported */
} lsm_capability_value_type;

/** \enum lsm_capability_value_type Capabilities supported by array */
diff --git a/c_binding/lsm_datatypes.cpp b/c_binding/lsm_datatypes.cpp
index fd77d29..01247c6 100644
--- a/c_binding/lsm_datatypes.cpp
+++ b/c_binding/lsm_datatypes.cpp
@@ -1569,7 +1569,7 @@ MEMBER_FUNC_GET(const char *, lsm_nfs_export_plugin_data_get,
lsm_capability_value_type lsm_capability_get(lsm_storage_capabilities *cap,
lsm_capability_type t)
{
- lsm_capability_value_type rc = LSM_CAPABILITY_UNSUPPORTED;
+ lsm_capability_value_type rc = LSM_CAP_UNSUPPORTED;

if( LSM_IS_CAPABILITIY(cap) && (uint32_t)t < cap->len ) {
rc = (lsm_capability_value_type)cap->cap[t];
@@ -1580,7 +1580,7 @@ lsm_capability_value_type lsm_capability_get(lsm_storage_capabilities *cap,
int LSM_DLL_EXPORT lsm_capability_supported(lsm_storage_capabilities *cap,
lsm_capability_type t)
{
- if( lsm_capability_get(cap, t) == LSM_CAPABILITY_SUPPORTED ) {
+ if( lsm_capability_get(cap, t) == LSM_CAP_SUPPORTED ) {
return 1;
}
return 0;
diff --git a/test/tester.c b/test/tester.c
index f4e19f4..1a27d12 100644
--- a/test/tester.c
+++ b/test/tester.c
@@ -1807,7 +1807,7 @@ static void cap_test( lsm_storage_capabilities *cap, lsm_capability_type t)

fail_unless ( lsm_capability_supported(cap, t) != 0,
"lsm_capability_supported returned unsupported");
- fail_unless( supported == LSM_CAPABILITY_SUPPORTED,
+ fail_unless( supported == LSM_CAP_SUPPORTED,
"supported = %d for %d", supported, t);
}

@@ -2054,7 +2054,7 @@ START_TEST(test_capability)
fail_unless(cap != NULL);

if( cap ) {
- G(rc, lsm_capability_set_n, cap, LSM_CAPABILITY_SUPPORTED,
+ G(rc, lsm_capability_set_n, cap, LSM_CAP_SUPPORTED,
LSM_CAP_VOLUMES,
LSM_CAP_VOLUME_CREATE,
LSM_CAP_VOLUME_RESIZE,
@@ -2102,14 +2102,14 @@ START_TEST(test_capability)
);

G(rc, lsm_capability_set, cap, LSM_CAP_EXPORTS,
- LSM_CAPABILITY_SUPPORTED);
+ LSM_CAP_SUPPORTED);

for( i = 0;
i < sizeof(expected_present)/sizeof(expected_present[0]);
++i) {

fail_unless( lsm_capability_get(cap, expected_present[i]) ==
- LSM_CAPABILITY_SUPPORTED);
+ LSM_CAP_SUPPORTED);
}

for( i = 0;
@@ -2117,7 +2117,7 @@ START_TEST(test_capability)
++i) {

fail_unless( lsm_capability_get(cap, expected_absent[i]) ==
- LSM_CAPABILITY_UNSUPPORTED);
+ LSM_CAP_UNSUPPORTED);
}
--
2.1.0
Tony Asleson
2014-08-28 14:28:08 UTC
Permalink
Patch series committed

Thanks,
Tony
Post by Gris Ge
Just some constant rename.
Utils: New script to compare constants in Python and C library
Rename Disk.DISK_TYPE_XXX to Disk.DISK
C Library: Rename LSM_CAPABILITY_XXX to LSM_CAP_XXX
Python Library: Trivial change: Allow script to easily check constants
.../libstoragemgmt/libstoragemgmt_capabilities.h | 4 +-
c_binding/lsm_datatypes.cpp | 4 +-
plugin/ontap/ontap.py | 30 +-
plugin/sim/simarray.py | 32 +-
plugin/smispy/smis.py | 22 +-
python_binding/lsm/_data.py | 51 ++-
test/tester.c | 10 +-
tools/lsmcli/data_display.py | 26 +-
tools/utility/check_const.pl | 489 +++++++++++++++++++++
9 files changed, 580 insertions(+), 88 deletions(-)
create mode 100644 tools/utility/check_const.pl
Continue reading on narkive:
Loading...