当前位置: 首页>>代码示例>>Python>>正文


Python OpenWrt.generate方法代码示例

本文整理汇总了Python中netjsonconfig.OpenWrt.generate方法的典型用法代码示例。如果您正苦于以下问题:Python OpenWrt.generate方法的具体用法?Python OpenWrt.generate怎么用?Python OpenWrt.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在netjsonconfig.OpenWrt的用法示例。


在下文中一共展示了OpenWrt.generate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_checksum

# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import generate [as 别名]
 def test_checksum(self):
     """ ensures checksum of same config doesn't change """
     o = OpenWrt({"general": {"hostname": "test"}})
     # md5 is good enough and won't slow down test execution too much
     checksum1 = md5(o.generate().getvalue()).hexdigest()
     sleep(1)
     checksum2 = md5(o.generate().getvalue()).hexdigest()
     self.assertEqual(checksum1, checksum2)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:10,代码来源:test_backend.py

示例2: test_file_inclusion

# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import generate [as 别名]
 def test_file_inclusion(self):
     o = OpenWrt({
         "files": [
             {
                 "path": "/etc/crontabs/root",
                 "mode": "0644",
                 "contents": '* * * * * echo "test" > /etc/testfile\n'
                             '* * * * * echo "test2" > /etc/testfile2'
             },
             {
                 "path": "/etc/dummy.conf",
                 "mode": "0644",
                 "contents": "testing!"
             }
         ]
     })
     output = o.render()
     self.assertNotIn('package files', output)
     self.assertIn('* * * * * echo', output)
     # ensure the additional files are there present in the tar.gz archive
     tar = tarfile.open(fileobj=o.generate(), mode='r')
     self.assertEqual(len(tar.getmembers()), 2)
     # first file
     crontab = tar.getmember('etc/crontabs/root')
     contents = tar.extractfile(crontab).read().decode()
     self.assertEqual(contents, o.config['files'][0]['contents'])
     self.assertEqual(crontab.mtime, 0)
     self.assertEqual(crontab.mode, 420)
     # second file
     dummy = tar.getmember('etc/dummy.conf')
     contents = tar.extractfile(dummy).read().decode()
     self.assertEqual(contents, o.config['files'][1]['contents'])
     self.assertEqual(dummy.mode, 420)
     tar.close()
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:36,代码来源:test_backend.py

示例3: test_file_permissions

# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import generate [as 别名]
 def test_file_permissions(self):
     o = OpenWrt({
         "files": [
             {
                 "path": "/tmp/hello.sh",
                 "mode": "0755",
                 "contents": "echo 'hello world'",
             }
         ]
     })
     tar = tarfile.open(fileobj=o.generate(), mode='r')
     script = tar.getmember('tmp/hello.sh')
     # check permissions
     self.assertEqual(script.mode, 493)
     tar.close()
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:17,代码来源:test_backend.py

示例4: test_generate

# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import generate [as 别名]
    def test_generate(self):
        o = OpenWrt({
            "interfaces": [
                {
                    "name": "wlan0",
                    "type": "wireless",
                    "addresses": [
                        {
                            "address": "192.168.1.1",
                            "mask": 24,
                            "proto": "static",
                            "family": "ipv4"
                        }
                    ],
                    "wireless": {
                        "radio": "radio0",
                        "mode": "access_point",
                        "ssid": "MyWifiAP",
                        "hidden": True
                    }
                }
            ],
            "radios": [
                {
                    "name": "radio0",
                    "phy": "phy0",
                    "driver": "mac80211",
                    "protocol": "802.11n",
                    "channel": 3,
                    "channel_width": 20,
                    "tx_power": 3
                }
            ]
        })
        tar = tarfile.open(fileobj=o.generate(), mode='r')
        self.assertEqual(len(tar.getmembers()), 2)
        # network
        network = tar.getmember('etc/config/network')
        contents = tar.extractfile(network).read().decode()
        expected = self._tabs("""config interface 'wlan0'
    option ifname 'wlan0'
    option ipaddr '192.168.1.1'
    option netmask '255.255.255.0'
    option proto 'static'

""")
        self.assertEqual(contents, expected)
        # wireless
        wireless = tar.getmember('etc/config/wireless')
        contents = tar.extractfile(wireless).read().decode()
        expected = self._tabs("""config wifi-device 'radio0'
    option channel '3'
    option htmode 'HT20'
    option hwmode '11g'
    option phy 'phy0'
    option txpower '3'
    option type 'mac80211'

config wifi-iface 'wifi_wlan0'
    option device 'radio0'
    option hidden '1'
    option ifname 'wlan0'
    option mode 'ap'
    option network 'wlan0'
    option ssid 'MyWifiAP'
""")
        self.assertEqual(contents, expected)
        tar.close()
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:70,代码来源:test_backend.py


注:本文中的netjsonconfig.OpenWrt.generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。