summaryrefslogtreecommitdiffstats
path: root/src/cmake/pack.cmake
blob: a89a90c452c584bbf8e5788e3d17e3514b2079a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Copyright (c) 2018 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# name, vendor, description are macros, arguments are in ${ARGN}
macro(add_vpp_packaging)
  cmake_parse_arguments(ARG
    ""
    "NAME;DESCRIPTION;VENDOR"
    ""
    ${ARGN}
  )

  # parse /etc/os-release
  file(READ "/etc/os-release" os_version)
  string(REPLACE "\n" ";" os_version ${os_version})
  foreach(_ver ${os_version})
    string(REPLACE "=" ";" _ver ${_ver})
    list(GET _ver 0 _name)
    list(GET _ver 1 _value)
    set(OS_${_name} ${_value})
  endforeach()

  # extract version from git
  execute_process(
    COMMAND git describe --long --match v*
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    OUTPUT_VARIABLE VER
    OUTPUT_STRIP_TRAILING_WHITESPACE
  )
  string(REGEX REPLACE "v(.*)-([0-9]+)-(g[0-9a-f]+)" "\\1;\\2;\\3" VER ${VER})
  list(GET VER 0 tag)
  list(GET VER 1 commit_num)
  list(GET VER 2 commit_name)

  #define DEB and RPM version numbers
  if(${commit_num} EQUAL 0)
    set(deb_ver "${tag}")
    set(rpm_ver "${tag}")
  else()
    if (DEFINED ENV{BUILD_NUMBER})
      set(deb_ver "${tag}~${commit_num}-${commit_name}~b$ENV{BUILD_NUMBER}")
      set(rpm_ver "${tag}~${commit_num}_${commit_name}~b$ENV{BUILD_NUMBER}")
    else()
      set(deb_ver "${tag}~${commit_num}-${commit_name}")
      set(rpm_ver "${tag}~${commit_num}_${commit_name}")
    endif()
  endif()

  set(CPACK_PACKAGE_NAME ${ARG_NAME})
  set(CPACK_STRIP_FILES OFF)
  set(CPACK_PACKAGE_VENDOR "${ARG_VENDOR}")
  set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
  set(CPACK_${CPACK_GENERATOR}_COMPONENT_INSTALL ON)
  set(CPACK_${type}_PACKAGE_DESCRIPTION "${ARG_DESCRIPTION}")
  set(CPACK_${type}_PACKAGE_RELEASE 1)

  if(OS_ID_LIKE MATCHES "debian")
    set(CPACK_GENERATOR "DEB")
    set(type "DEBIAN")
    set(CPACK_PACKAGE_VERSION "${deb_ver}")
    set(CPACK_DEBIAN_PACKAGE_MAINTAINER "VPP Team")
    execute_process(
      COMMAND dpkg --print-architecture
      OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
      OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
  elseif(OS_ID_LIKE MATCHES "rhel")
    set(CPACK_GENERATOR "RPM")
    set(type "RPM")
    set(CPACK_PACKAGE_VERSION "${rpm_ver}")
    execute_process(
      COMMAND uname -m
      OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE
      OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CPACK_RPM_PACKAGE_ARCHITECTURE})
  endif()

  if(CPACK_GENERATOR)
    include(CPack)
  else()
    message(ERROR "CPACK_GENERATOR must be set")
  endif()

endmacro()
an class="n">local_ip4_prefix_len = 32 i.config_ip4() i.admin_up() # read (check sw if dump, ip4 fib, ip6 fib) if_dump = self.vapi.sw_interface_dump() fib4_dump = self.vapi.ip_route_dump(0) for i in loopbacks: self.assertTrue(i.is_interface_config_in_dump(if_dump)) self.assertTrue(i.is_ip4_entry_in_fib_dump(fib4_dump)) # check ping stream = self.create_icmp_stream(self.pg0, loopbacks) self.pg0.add_stream(stream) self.pg_enable_capture(self.pg_interfaces) self.pg_start() capture = self.pg0.get_capture(expected_count=len(stream)) self.verify_icmp(capture, self.pg0, loopbacks) # delete for i in loopbacks: i.remove_vpp_config() # read (check not in sw if dump, ip4 fib, ip6 fib) if_dump = self.vapi.sw_interface_dump() fib4_dump = self.vapi.ip_route_dump(0) for i in loopbacks: self.assertFalse(i.is_interface_config_in_dump(if_dump)) self.assertFalse(i.is_ip4_entry_in_fib_dump(fib4_dump)) # check not ping stream = self.create_icmp_stream(self.pg0, loopbacks) self.pg0.add_stream(stream) self.pg_enable_capture(self.pg_interfaces) self.pg_start() self.pg0.assert_nothing_captured() def test_down(self): # create loopbacks = self.create_loopback_interfaces(20) for i in loopbacks: i.local_ip4_prefix_len = 32 i.config_ip4() i.admin_up() # disable for i in loopbacks: i.admin_down() i.unconfig_ip4() # read (check not in sw if dump, ip4 fib, ip6 fib) if_dump = self.vapi.sw_interface_dump() fib4_dump = self.vapi.ip_route_dump(0) for i in loopbacks: self.assertTrue(i.is_interface_config_in_dump(if_dump)) self.assertFalse(i.is_ip4_entry_in_fib_dump(fib4_dump)) # check not ping stream = self.create_icmp_stream(self.pg0, loopbacks) self.pg0.add_stream(stream) self.pg_enable_capture(self.pg_interfaces) self.pg_start() self.pg0.assert_nothing_captured() class TestInterfaceDumpApiLocalOnly(VppTestCase): """test_interface_crud.TestInterfaceDumpApiLocalOnly""" def test_sw_if_index_0(self): rv = self.vapi.sw_interface_dump(sw_if_index=0) self.assertEqual(rv[0].sw_if_index, 0) def test_sw_if_index_twiddle0(self): rv = self.vapi.sw_interface_dump(sw_if_index=0xffffffff) self.assertEqual(rv[0].sw_if_index, 0) def test_sw_if_index_1_not_existing(self): rv = self.vapi.sw_interface_dump(sw_if_index=1) self.assertEqual(len(rv), 0, 'expected no records.') class TestInterfaceDumpApi(VppTestCase): """test_interface_crud.TestInterfaceDumpApi""" def test_sw_if_index_1(self): self.vapi.create_loopback_instance(is_specified=1, user_instance=10) self.vapi.create_loopback_instance(is_specified=1, user_instance=5) # Can I get back the specified record? rv = self.vapi.sw_interface_dump(sw_if_index=1) self.assertEqual(rv[0].sw_if_index, 1, rv) # verify 3 interfaces rv = self.vapi.sw_interface_dump(sw_if_index=0xffffffff) self.assertEqual(len(rv), 3, 'Expected 3 interfaces.') if __name__ == '__main__': unittest.main(testRunner=VppTestRunner)